论坛首页 综合技术论坛

ssh其他机器的Expect脚本

浏览 2618 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2011-10-11  

ssh登陆其他机器的Expect脚本

 

#!/usr/bin/expect -f

set user [lindex $argv 0]
set ipaddr [lindex $argv 1]
set passwd [lindex $argv 2]

spawn ssh -l $user $ipaddr

expect "password:"
send "$passwd\r"
interact
 

或者:

 

#!/usr/bin/expect -f

set user [lindex $argv 0]
set ipaddr [lindex $argv 1]
set passwd [lindex $argv 2]

spawn ssh -l $user $ipaddr

expect {
 "password:" { send "$passwd\r";}
}

interact

 

或者:

 

#!/usr/bin/expect -f

set user [lindex $argv 0]
set ipaddr [lindex $argv 1]
set passwd [lindex $argv 2]

spawn ssh -l $user $ipaddr

expect "password:"
    send "$passwd\r"
expect eof

interact
 

 

 

 

 

 

 

 

 

 

论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics