期望脚本启动 ilo2,工作正常但无法退出

期望脚本启动 ilo2,工作正常但无法退出

这是我启动 ILO2 HP 服务器的脚本。工作正常(服务器电源打开),但在 iLO 控制台电源保持打开状态后,我只能手动使用 ctrl+c 退出脚本,因此脚本不是完全非交互式的,如何将正确的 ^D 传递给从控制台退出?

#!/usr/bin/expect -f

set force_conservative 0  ;# set to 1 to force conservative mode even if
              ;# script wasn't run conservatively originally
if {$force_conservative} {
    set send_slow {1 .1}
    proc send {ignore arg} {
        sleep .1
        exp_send -s -- $arg
    }
}

set timeout -1
set send_slow {1 .1}
spawn csh
match_max 100000
expect -exact "% "
sleep .1
send -s -- "ssh hpilo2\r"
expect -exact "ssh hpilo2\r\r
This is a private system. It is to be used solely by authorized users and may be monitored for all lawful purposes. By accessing this system, you are consenting to such monitoring.\r
\rmyuser@hpilo2's password: "
sleep .1
send -s -- "mypass\r"
expect -exact "\r
User:myuser logged-in to hpilo2.(******* / *********)\r
\r
iLO Advanced **** at  Feb 28 2041\r
Server Name: \r
Server Power: Off\r
\r
</>hpiLO-> "
sleep .1
send -s -- "power on\r"
expect -exact "
\r\r
status=0\r
status_tag=COMMAND COMPLETED\r
Sat Dec 6 12:38:17 2031
\r
\r
\r
Server powering on .......\r
\r
\r
\r
</>hpiLO-> "
sleep .1
send -- "^D"
expect eof

答案1

解决方案发现 CTRL+D 在我的 hpilo shell 上什么也不做,退出 shell 的命令是..退出。所以我修改了脚本的最新行

Server Name: \r
Server Power: Off\r
\r
</>hpiLO-> "
sleep .1
send -s -- "power on\r"
sleep 2
send -s -- "^exit\r"

现在工作完美

相关内容