建立信任关系后的远程操作

创建信任关系的过程,请参考文章:

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"

 

 

你可能感兴趣的:(建立信任关系后的远程操作)