分享一个expect的脚本

分享一个expect的脚本,可以用于Linux机器之间远程执行命令:

 

 

#!/usr/bin/expect -f

set ipaddress [lindex $argv 0]
set user [lindex $argv 1]
set passwd [lindex $argv 2]
set cmd [lindex $argv 3]
set timeout [lindex $argv 4]

spawn -noecho ssh $user@$ipaddress $cmd

expect {
"yes/no" { send "yes\r";exp_continue}
"*assword:" { send "$passwd\r";exp_continue}
#"]*" { send "$cmd\r"}
}
#expect eof

你可能感兴趣的:(linux,bash,expect)