您的位置:首页 > 运维架构 > Shell

shell+expect实现多台服务器自动运行脚本。

2013-07-08 17:16 691 查看
list.txt

192.168.1.1:root:passwd

192.168.1.2:root:passwd



192.168.1.50:root:passwd

cat/root/list.txt |

whileread row;do

IP=$(echo $row |cut -d : -f 1 )

username=$(echo $row |cut -d : -f 2 )

passwd=$(echo $row |cut -d : -f 3 )

pr='sysctl –w –q net.ipv4.tcp_tw_reuse = 1'

/usr/bin/expect -f /root/abc.sh"$IP" "$username" "$passwd" "$pr"

done

expect.sh

#!/usr/bin/expect -f

setip [lindex $argv 0]

setusername [lindex $argv 1]

setpassword [lindex $argv 2]

settimeout 10

spawn ssh$username@$ip

expect {

"*yes/no"{ send "yes\r"; exp_continue}

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

}

expect"#*"

send"[lindex $argv 3]\r"

send "exit\r"

expecteof
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: