奇怪的行为期望cron下的脚本

时间:2015-08-10 14:59:02

标签: ubuntu cron expect

我有简单的期望脚本

#!/usr/local/bin/expect -f

#TFTP

exp_internal 1
log_file expect.stdout.log

set timeout 60
set hostname [lindex $argv 0];
set login [lindex $argv 1];
set password [lindex $argv 2];
set iptftp [lindex $argv 3];
set file [lindex $argv 4];

match_max 1000000
spawn telnet $hostname

sleep 1
expect "login:" {send "$login\n"}
sleep 1
expect "Password:" {send "$password\n"}
sleep 3
expect "*#" {send -- "upload cfg_toTFTP $iptftp $file config_id 1\n"}
sleep 3

expect "*#" {send -- "logout\n"}

此脚本通过php脚本运行,该脚本连接到mysql DB并获取主机名,登录等。如果我通过shell / usr / bin / php /home/swbackup/backup.php运行脚本 - 一切正常。在cron下,脚本登录后切换只发送命令上传的第一个字母cfg_toTFTP u ,仅此而已

expect: does " \r\n\r\n\rDGS-1100-06/ME:5# " (spawn_id exp7) match glob pattern "*#"? yes
expect: set expect_out(0,string) " \r\n\r\n\rDGS-1100-06/ME:5#"
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) " \r\n\r\n\rDGS-1100-06/ME:5#"
send: sending "upload cfg_toTFTP 10.0.4.240 174610_backup.cfg config_id 1\n" to { exp7 }

expect: does " " (spawn_id exp7) match glob pattern "*#"? no
u
expect: does " u" (spawn_id exp7) match glob pattern "*#"? no
Connection closed by foreign host.

我尝试了不同的选项,但没有任何帮助

0 个答案:

没有答案