【发布时间】:2022-04-21 15:13:03
【问题描述】:
任务是每晚远程重启 ip-phones。
sshpass:sshpass -p 12345678 ssh -o StrictHostKeyChecking=no admin@192.168.2.1 reboot
作为回应:到 192.168.2.1 的连接已被远程主机关闭。
此外,电话在 CLI 中像往常一样要求回答 y。
预期:
COMM="
log_file debug.log
exp_internal 1
set timeout 5
spawn ssh admin@192.168.2.1
expect \"password:\"
send \"12345678\r\"
sleep 5
expect \"*>\"
send \"reboot\r\"
sleep 5
expect \"*y/N*\"
send \"y\r\"
expect eof
"
expect -c "$COMM"
当我自己从控制台执行此操作时,一切正常。使用cron,在debug.log中,由于某种原因,在设备上授权后,没有出现输入expect \"*>\"命令的行。即使我们删除 expect \"*>\" 并仅使用 send,也没有任何反应。
我寻求解决问题的提示或提出其他解决方案。谢谢。
控制台和 cron 之间的 debug.log 不同
控制台:
expect: does " \r\n" (spawn_id exp5) match glob pattern "*>"? no
^[[1;36m
expect: does " \r\n\u001b[1;36m\r\n\t" (spawn_id exp5) match glob pattern "*>"? no
Grandstream GXV3240 Command-Line Interface Copyright 2017
Grandstream Networks, Inc.
^[[0m
GXV3240>
expect: does " \r\n\u001b[1;36m\r\n\tGrandstream GXV3240 Command-Line Interface Copyright 2017\r\n\t\tGrandstream Networks, Inc.\r\n\u001b[0m\r\nGXV3240> " (spawn_id exp5) match glob pattern "*>"? yes
expect: set expect_out(0,string) " \r\n\u001b[1;36m\r\n\tGrandstream GXV3240 Command-Line Interface Copyright 2017\r\n\t\tGrandstream Networks, Inc.\r\n\u001b[0m\r\nGXV3240>"
expect: set expect_out(spawn_id) "exp5"
expect: set expect_out(buffer) " \r\n\u001b[1;36m\r\n\tGrandstream GXV3240 Command-Line Interface Copyright 2017\r\n\t\tGrandstream Networks, Inc.\r\n\u001b[0m\r\nGXV3240>"
send: sending "reboot\r" to { exp5 }
cron:
expect: does " " (spawn_id exp4) match glob pattern "*>"? no
^[[1;36m
Grandstream GXV3240 Command-Line Interface Copyright 2017
Grandstream Networks, Inc.
^[[0m
^[[6n
expect: does " \r\n\u001b[1;36m\r\n\tGrandstream GXV3240 Command-Line Interface Copyright 2017\r\n\t\tGrandstream Networks, Inc.\r\n\u001b[0m\r\n\u001b[6n" (spawn_id exp4) match glob pattern "*>"? no
expect: timed out
send: sending "reboot\r" to { exp4 }
expect: does " \r\n\u001b[1;36m\r\n\tGrandstream GXV3240 Command-Line Interface Copyright 2017\r\n\t\tGrandstream Networks, Inc.\r\n\u001b[0m\r\n\u001b[6n" (spawn_id exp4) match glob pattern "*y/N*"? no
expect: timed out
【问题讨论】: