expect
Posted tintindeng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了expect相关的知识,希望对你有一定的参考价值。
登陆
#!/usr/bin/expect
set port 22
set user root
set host 192.168.1.26
set password xxx
spawn ssh -l $user $host
expect {
"*yes/no" {send "yes\r"}
"*password:" {send "$password\r"}
}
#expect eof
interact
切换用户
#!/usr/bin/expect
set timeout 3
spawn su root
sleep 1
expect {
"密码*" {send "xxx\r"}
}
send "cd /etc/openvpn/ \r"
send "openvpn client.ovpn \r"
interact
上传包
#!/usr/bin/expect
set password xxx
spawn scp -r /home/y/deploy [email protected]:/home/war
expect {
"*yes/no" {send "yes\r"; exp_continue}
"*password:" { send "$password\r"}
}
interact
set user root
set host 155.55.55.44
set password xxx
spawn ssh -l $user $host
expect {
"*yes/no" {send "yes\r"; exp_continue}
"*password:" { send "$password\r"}
}
send "rm -rf ~/scp \r"
sleep 1
send "cat>scp<<EOF \r"
send "#!/usr/bin/expect \r"
send "spawn scp -r /home/war/deploy/ [email protected]:/home/ftpadmin/apache-tomcat-7.0.62/webapps/ \r"
send "expect { \r"
send "\"*yes/no\" {send \"yes\\r\"; exp_continue} \r"
send "\"*password:\" { send \"$password\\r\"}} \r"
send "interact \r"
send "EOF"
send "\r"
send "chmod 777 scp \r"
send "history -c \r"
send "./scp \r"
#interact
expect eof
以上是关于expect的主要内容,如果未能解决你的问题,请参考以下文章