- 论坛徽章:
- 0
|
本帖最后由 pyartist 于 2015-09-02 00:12 编辑
一级登录投入命令这个我已经实现- #!/usr/bin/expect -f
- set ip [ lindex $argv 0 ]
- set passwd [ lindex $argv 1 ]
- set cmd [ lindex $argv 2 ]
- set timeout 10000
- spawn ssh root@$ip
- expect {
- "*yes/no" { send "yes\n"; exp_continue}
- "*password:" { send "$passwd\n"}
- "# " {send "\n"}
- }
- expect "# "
- send "$cmd\n"
- expect "# "
- send "exit\n"
- expect eof
复制代码 但是两级登录如何实现,我仿造上面写了个,但是不能执行通过- #!/usr/bin/expect -f
- set ip [ lindex $argv 0 ]
- set passwd [ lindex $argv 1 ]
- set ip2 [ lindex $argv 2 ]
- set passwd2 [ lindex $argv 3 ]
- set cmd [ lindex $argv 4 ]
- set timeout 10000
- spawn ssh root@$ip
- expect {
- "*yes/no" { send "yes\n"; exp_continue}
- "*password:" { send "$passwd\n"}
- "# " {send "\n"}
- }
- expect "# "
- spawn ssh root@$ip2
- expect {
- "*yes/no" { send "yes\n"; exp_continue}
- "*password:" { send "$passwd2\n"}
- "# " {send "\n"}
- }
- send "$cmd\n"
- expect "# "
- send "exit\n"
- expect eof
复制代码 请教如何实现两级ssh登录,就是先ssh登录到一台主机,再从新登录的主机上ssh到另外一台主机 |
|