【发布时间】:2012-02-27 10:19:54
【问题描述】:
当 Linux 机器的 $IP 在登录后询问密码时,以下期望脚本可以正常工作
但是在某些情况下,一些Linux机器不需要ssh密码(我们可以不用密码登录),
所以我需要更改我的期望脚本以支持没有密码的机器
请建议如何适应我的期望脚本,以支持有密码的机器和没有密码的机器
* target of the following expect script is to check the hostname on remote Linux machine
expect_test=`cat << EOF
set timeout -1
spawn ssh $IP hostname
expect {
")?" { send "yes\r" ; exp_continue }
word: {send "pass123\r" }
}
expect eof
EOF`
expect -c "$expect_test"
远程机器上的 exe 示例(带密码)(远程机器的名称 - Linux1_machine)
IP=10.17.18.6
expect -c "$expect_test"
spawn ssh 10.17.18.6 hostname
sh: /usr/local/bin/stty: not found
This computer system, including all related equipment, networks and network devices (specifically including Internet access),is pros
yes
Password:
Linux1_machine
在不需要密码登录的机器上执行expect脚本的例子
IP=10.10.92.26
expect -c "$expect_test"
spawn ssh 10.10.92.26 hostname
sh: /usr/local/bin/stty: not found
Linux15_machine
expect: spawn id exp5 not open
while executing
"expect eof"
【问题讨论】:
标签: linux bash shell ksh expect