加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

day 11 分发系统

发布时间:2020-12-15 23:05:36 所属栏目:安全 来源:网络整理
导读:[[email?protected] ~] # fg vim 1 .expect # 远程登陆 # !/usr/bin/expect set host "" set passwd "" spawn ssh [email?protected]$hostexpect { " yes/no " { send " yesr " ; exp_continue} " assword: " { send " $passwdr " }}interact # 远程登陆并
[[email?protected] ~]# fg
vim 1.expect
#远程登陆
#!/usr/bin/expect
set host ""
set passwd ""
spawn ssh [email?protected]$host
expect {
"yes/no" { send "yesr"; exp_continue}
"assword:" { send "$passwdr" }
}
interact
#远程登陆并执行命令
#!/usr/bin/expect
set user ""
set passwd ""
spawn ssh [email?protected]
expect {
"yes/no" { send "yesr"; exp_continue}
"password:" { send "$passwdr" }
}
expect "]*"
send "touch /tmp/1.txtr"
expect "]*"
send "echo 22222 > /tmp/1.txtr"
expect "]*"
send "exitr"

~                                                                                                                                       
~       

?

#传递参数
#!/usr/bin/expect
set user [lindex $argv 0]
set host [lindex $argv 1]
set passwd ""
set cm [lindex $argv 2]
spawn ssh [email?protected]$host
expect {
"yes/no" { send "yesr"}
"password:" { send "$passwdr" }
}
expect "]*"
send "$cmr"
expect "]*"
send "exitr"

~                                                                                                                                       
~                                                                                                                                       
~                     
#同步文件
#!/usr/bin/expect
set passwd ""
spawn rsync -av [email?protected]  :/tmp/1.txt /tmp/
expect {
"yes/no" { send "yesr"}
"password:" { send "$passwdr" }
}
expect eof

shell项目-分发系统-构建文件分发系统

核心命令rsync -av --files-from=list.txt??/??[email?protected]:/

[[email?protected] expect]# vim rsync.expect
#!/usr/bin/expect
set passwd ""
set host [lindex $argv 0]
set file [lindex $argv 1]
spawn rsync -av --files-from=$file / [email?protected]$host:/
expect {
"yes/no" { send "yesr"}
"password:" { send "$passwdr" }
}
expect eof
~      

#遍历ip.list选择需要同步的IP,遍历list.txt选择需要同步的文件
[[email?protected] expect]# vim rsync.sh
#!/bin/bash
for ip in `cat ip.list`
do
? ? echo $ip
? ? ./rsync.expect $ip list.txt
done
          

shell项目-分发系统-命令批量执行

[[email?protected] expect]# vim exe.expect

#!/usr/bin/expect
set host [lindex $argv 0]
set passwd ""
set cm [lindex $argv 1]
spawn ssh [email?protected]$host
expect {
"yes/no" { send "yesr"}
"password:" { send "$passwdr" }
}
expect "]*"
send "$cmr"
expect "]*"
send "exitr"
#遍历文件批量执行命令
[[email?protected] expect]# vim exe.sh

#!/bin/bash
for ip in `cat ip.list`
do
? ? echo $ip
? ? ./exe.expect $ip "w;free -m;ls /tmp"
done

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读