码迷,mamicode.com
首页 > 其他好文 > 详细

expect

时间:2016-12-11 01:22:52      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:cli   0.12   ssh   sleep   port   admin   tom   host   webapp   

登陆

#!/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 root@15.55.55.55:/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/ root@10.12.22.22:/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

标签:cli   0.12   ssh   sleep   port   admin   tom   host   webapp   

原文地址:http://www.cnblogs.com/tintindeng/p/6158357.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!