自动化交互工具 - expect
expect.sh版
#!/usr/bin/expect
set user "root"
set ip "192.168.30.90"
set passwd "123123"
spawn ssh $user@$ip
expect {
"yes/no" {send "yes\n";exp_continue} #加上exp_continue程序不会退出该条expect
"password" {send "$passwd\n"}
}
expect "#"
send "ls\n"
expect "#"
send "exit\n"
expect eof
shell.sh版
#!/bin/bash
user="root"
ip="192.168.30.90"
passwd="123123"
expect << EOF
spawn ssh $user@$ip
expect {
"yes/no" {send "yes\r";exp_continue}
"password" {send "$passwd\r"}
}
expect "#"
send "ls\r"
expect "#"
send "exit\r"
expect eof
EOF
``
#!/usr/bin/expect
set user "root"
set ip "192.168.30.90"
set passwd "123123"
spawn ssh $user@$ip
expect {
"yes/no" {send "yes\n";exp_continue} #加上exp_continue程序不会退出该条expect
"password" {send "$passwd\n"}
}
expect "#"
send "ls\n"
expect "#"
send "exit\n"
expect eof
shell.sh版
#!/bin/bash
user="root"
ip="192.168.30.90"
passwd="123123"
expect << EOF
spawn ssh $user@$ip
expect {
"yes/no" {send "yes\r";exp_continue}
"password" {send "$passwd\r"}
}
expect "#"
send "ls\r"
expect "#"
send "exit\r"
expect eof
EOF
``
如有问题请联系我 QQ:1021395023

浙公网安备 33010602011771号