标签:
创建信任关系的过程,请参考文章:
http://blog.csdn.net/jiangshouzhuang/article/details/12650091
信任关系创建完成后,就可以远程执行命令了,脚本如下:
#!/usr/bin/expect
set username [lindex $argv 0]
set server_ip [lindex $argv 1]
set command [lindex $argv 2]
set timeout 10
if {$argc<3} {
puts stderr "the argument number for execute remote command is not right .\n"
exit 1
}
spawn ssh $username@$server_ip
expect {
"*yes/no)" {send "yes\r";exp_continue}
}
send "$command\r"
expect "eof"
send "exit\r"
标签:
原文地址:http://blog.csdn.net/jiangshouzhuang/article/details/7647934