在ksh脚本中调用expect脚本就会挂起

时间:2017-04-11 19:25:39

标签: shell expect

我有一个autoexpect生成的expect脚本,我在korn shell脚本中调用。这是我的脚本的内容:

#!/usr/bin/ksh
/usr/bin/expect /home/user1/script.exp

如果我在命令行上运行上面的命令,它运行正常。但是如果我把它放在shell脚本中(所以我可以在cron中安排它),它只是挂起并且永远不会返回任何内容,日志文件只显示:

spawn /bin/bash

有人可以提出任何建议吗?

谢谢!

#!/usr/bin/expect -f

set force_conservative 1  ;# 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
spawn $env(SHELL)
match_max 100000
expect -exact "]0;daily@tatooine:~\[daily@tatooine ~\]\$ "
send -- "su -"
expect -exact "su -[K"
send -- "\r"

。 。

1 个答案:

答案 0 :(得分:0)

您可以通过添加标志-d:

来调试发生的事情
/usr/bin/expect -d /home/user1/script.exp
相关问题