linux expect脚本文件分发系统

来源:互联网 发布:在淘宝怎么买电棍 编辑:程序博客网 时间:2024/05/22 18:55

(以下示例思路来自猿课阿铭linux)

远程分发文件基础知识

scp 文件 目标IP:绝对路径

scp 1.txt 192.168.153.134:/tmp/

远程分发目录

scp -r

 

rsync  增量备份(本地远程都可用)

rsync -av 文件目录  目标IP:目标目录

 

构建文件分发系统

使用expect脚本批量把需要同步的文件分发到目标机器

核心命令 :rsync -av –files-from=list.txt /root@hostname:/

实现:

cat rsync.expect

#!/usr/bin/expect

set passwd "*******"

set host [lindex $argv 0]

set file [lindex $argv 1]

spawn rsync -av --files-from=$file /root@$host:/

expect {

"yes/no" { send"yes\r"}

"password:" { send "$passwd\r"}

}

expect eof

 

cat ip.list

192.168.153.134

192.168.153.135

192.168.153.136

192.168.153.137

 

cat rsync.sh

#!/bin/bash

for ip in `cat ip.list`

do

       echo$ip

       ./rsync.expect$ip list.txt

done

 

cat list.txt

/root/1.expect

/tmp/1.txt

/tmp/a.txt

/tmp/A.txt

/tmp/b.txt

/tmp/B.txt

 

命令批量执行脚本

 

cat exe.expect

#!/usr/bin/expect

set host [lindex $argv 0]

set passwd "********"

set cm [lindex $argv 1]

 

spawn ssh root@$host

 

expect {

"yes/no" { send"yes\r"}

"password:" { send"$passwd\r" }

}

expect "]*"

send "$cm\r"

expect "]*"

send "exit\r"

 

cat exe.sh

#!/bin/bash

for ip in `cat ip.list`

do

       echo$ip

       ./exe.expect$ip 'free;ls /tmp'

done

 

cat ip.list

192.168.153.134

192.168.153.135

192.168.153.136

192.168.153.137

阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 华友源儿童内衣 华友源 华友源内衣 华君武 锦梅馨苑 金榜家园 剑桥景苑 普乐二村 华商论坛 华商价值 华商国际 华商策略 华商红利 华商集团 华商报 华商报电子版 华商报电话 华商报登报电话 西安华商报招聘信息 西安华商报 华商领先 华商学院 华商 普华商学院 华商银行 华商基金 广州华商 华商金地 广州华商职业学院 山西财经华商学院 华商未来主题 华商领先基金净值 华商盛世成长基金净值 华商教务系统 华商领先企业基金净值 华商精选基金净值 华商领先企业 华商价值精选基金净值 630001华商领先企业 000800华商未来主题 华商领先企业天天基金