创建了这个简单的脚本,以便在思科(远程呈现)CTS1300,1000和3000编解码器上执行重启。目标是通过使用cron每周重启一堆这些单元。我正在使用Cygwin,这是期望脚本:
#!/usr/bin/expect -f
spawn ssh AdminUser@123.123.123.123
expect "*?assword:*"
send -- "MyPassword\r"
expect "*admin:*"
"send -- "utils system restart\r"
expect -exact "Are you sure you want to perform a System Restart ?\r
Enter \"yes\" to Restart the System or any other key to abort\r
continue: "
send -- "yes\r"
expect "*admin:*"
send -- "quit\r"
expect eof
输出结果为:
superuser@SUPERPC ~/ctspsswd
./restartall2
spawn ssh AdminUser@123.123.123.123
AdminUser@123.123.123.123's password:
Command Line Interface is starting up, please wait ...
Welcome to the TelePresence Command Line Interface (version 1.1)
admin:utils system restart
Are you sure you want to perform a System Restart ?
Enter "yes" to Restart the System or any other key to abort
continue: s
The System Restart has been aborted
admin:quit
Connection to 123.123.123.123 closed.
出于一些奇怪的原因,它只发送“s”,它会中止系统重启。
我尝试使用#!/bin/bash
类型脚本,输出类似。
我尝试使用wild chars for expect "*continue:*"
,但仍然有类似的输出。
我尝试使用autoexpect
,同样的事情发生了。 Autoexpect脚本看起来与我的脚本非常相似,只是对我输入的每个字符更具体。
我尝试在发送utils系统重启后立即发送yes
,结果只相当于\r
。
有什么我想念的吗?否则,我将创建一个脚本,该脚本将使用yes
部分的交互。