当cron运行时,期望脚本运行屏幕停止工作

我希望这个问题是可以的这个论坛。

我有一个设备,一个调制解调器。 我把这个调制解调器与linux程序“screen”作为一个terminal程序。 我像这样调用它“ /usr/bin/screen /dev/tty6 ”。 我需要每个会话发送大约6个命令。 我使用期望的脚本,所以我可以自动化的过程。 期望脚本产生屏幕过程,发送命令然后退出。

当我从terminal会话运行它时,或者当我使用另一台机器上的ssh远程运行它时,该系统工作正常。 但是当我用cron运行它时,它失败了。 在本地机器上,它会失败,出现如下错误: spawn id exp6 not open while executing exp_send 。 这是在第三次发送预期的脚本。

我尝试使用cron远程使用ssh-t-tt-ttt选项运行,但是我得到错误:“ Pseudo-terminal will not be allocated because stdin is not a terminal.

我的crontabs有一个pathvariables集,然而大部分命令都是用完整的path调用的,我很确定。

我尝试使用-m选项尝试产卵屏幕,但它仍然显然产生失败。 产卵屏幕和分离它在这种情况下没有任何意义。 部分问题似乎是运行屏幕作为terminal仿真器到串口不同于正常运行。 任何帮助或见解将不胜感激。

期望的脚本在这里:

— DO-stuff.exp

 #!/usr/bin/expect -b set verbose 0 set verb [lindex $argv 0] if { $verb eq "-v" } { set ::argv [lassign $::argv verbose] set verbose 1 } set phone [lindex $argv 0] set message [lindex $argv 1] if { $verbose == 1 } { send_user "phone = ($phone)\n" send_user "message = ($message)\n" } set force_conservative 1 ;# set to 1 to force conservative mode even if if {$force_conservative} { set send_slow {1 .1} proc send {ignore arg} { sleep .1 exp_send -s -- $arg } } # turn off screen echo if { $verbose == 0 } { log_user 0 } set timeout -1 spawn /usr/bin/screen /dev/tty6 cs8 match_max 100000 # wait 100 milliseconds after 100 send -- "+++" after 100 send -- "ATZ\r" expect -exact "OK\r " send -- "AT+CMGF=1\r" expect -exact "OK\r " send -- "AT+CMGS=\"$phone\"\r" expect -exact " > " send -- "$message\r" expect -exact "\r > " send -- "^Z" expect -exact "OK\r " send -- "^Ak" after 500 send -- "y" #expect eof exit 0 

——– cron选项卡

/etc/cron.d/local-test

 SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # mh dom mon dow user command */3 * * * 1-5 fred /home/fred/do-stuff.exp -- -v 12345678 "test message cron 2" 

cron电子邮件

 phone = (123456789) message = (test message cron 2) spawn /usr/bin/screen /dev/tty6 cs8 Please set a terminal type. +++ATZ send: spawn id exp6 not open while executing "exp_send -s -- $arg" (procedure "send" line 3) invoked from within "send -- "AT+CMGF=1\r"" 

它看起来像我只需要添加:

 TERM=vt100 

到我的cronfile。 哎哟。

现在所有的工作。