一个简单的expect脚本。expect在不是root用户情况下,据说很慢。。
强烈推荐使用perl的expect,速度快很多。
#!/usr/local/bin/expect
set timeout 40
#$argv 0 means the 1st argument, give its value to variable host
set host [lindex $argv 0]
#run the shell command
spawn scp ./nrpe_RHEL6_x86_.tar.gz user@$host:/tmp
expect {
"/no)?" {send "yes\r";exp_continue}
"assword:" {send "Password\r";exp_continue}
}
spawn ssh user@$host
expect {
"/no)?" {send "yes\r";exp_continue}
"assword:" {send "Password\r";exp_continue}
}
expect "$"
send "sudo su -\r"
expect "#"
send "cd /tmp\r"
send "yum -y install redhat-lsb\r"
send "yum -y install openssl\r"
send "./install Linux\r"
send "exit\r"
expect eof
阅读(1073) | 评论(0) | 转发(0) |