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
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
相关文章推荐
- 用expect实现的自动登录到多台服务器的shell脚本
- 用expect实现的自动登录到多台服务器的shell脚本
- linux系统shell脚本实现 恶意扫描服务器密码 自动屏蔽
- 通过crond自动运行Python脚本实现多台linux服务器的监控
- 在shell脚本中利用expect实现自动应答
- shell脚本通过expect实现自动单边无密登录
- Shell脚本实现自动输入密码登录服务器
- Shell脚本实现自动输入密码登录服务器
- 在shell脚本中利用expect实现自动应答
- Shell 和 Expect 脚本的自动登录运行
- shell脚本通过expect实现自动单边无密登录功能
- shell脚本通过expect脚本实现自动输入密码
- shell脚本实现多台服务器自动巡检--可参考学习
- Shell脚本中调用expect,实现自动输入密码的功能
- 【转】在shell脚本中利用expect实现自动应答
- linux使用shell脚本实现自动登录scp传输文件到其他服务器
- shell脚本通过expect脚本实现自动输入密码(使用expect)
- shell脚本调用expect命令实现命令行自动交互
- 【转】shell脚本实现多台服务器自动巡检--可参考学习
- linux系统shell脚本实现 恶意扫描服务器密码 自动屏蔽