我正在尝试使用send and Expect ssh模块在远程UNIX主机上执行命令,但是即使脚本成功登录到服务器,它也不会执行命令。
#!/usr/bin/expect
set timeout 60
spawn ssh xxxx@xxxxxx
expect "yes/no" {
send "yes\r"
expect "*?assword" { send "xxxxxx\r" }
} "*?assword" { send "xxxxxxx\r" }
expect "$ "
#sleep 5
send "ps -aef \r"
输出
[xxxxx@xxxxxx Scripts]$ ./TestExpect.sh
spawn ssh xxxxx@xxxxxx
xxxxxx@xxxxxx's password:
Last login: Wed May 9 02:05:47 2018 from xxxxxxxxx
Kickstarted on 2015-05-12
[xxxxx@xxxxx ~]$ [xxxxxx@xxxxx Scripts]$
提示如下
[aacdd123@linprod345 ~]$
白衣非少年