首页 > 代码库 > expect

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 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