我希望脚本过早关闭

时间:2018-01-22 18:30:22

标签: linux bash ssh expect

我试图使用expect脚本将borg备份发送到远程服务器并修剪旧服务器。发送备份的脚本运行正常。但是,在修剪任何备份之前,修剪存档的脚本会超时。我已经确认手动运行命令确实有效。有什么想法,为什么它超时?

#!/usr/bin/expect

set folder [exec bash -c "ls -td /home/.snapshots/* | head -n 1"];
set otp [exec oathtool --totp -b KEY];

spawn borg prune --keep-hourly 5 --keep-daily 7 --keep-weekly 4 --keep-monthly 3 --keep-yearly 1 --prefix='home' ssh://user@host:PORT/ARCHIVE

expect "Enter passphrase for key '/root/.ssh/id_ed25519': "
send -- "PASSWORD\r"

expect "Verification code: "
send -- "$otp\r"

expect "Enter passphrase for key ssh://user@host:PORT/ARCHIVE: "
send -- "PASSWORD\r"

expect eof
wait

1 个答案:

答案 0 :(得分:1)

默认预期超时为10秒,如果您的修剪操作运行时间超过10秒且未产生任何输出,则预计会超时。

您应该将脚本开头的超时设置为2分钟,例如:

#!/usr/bin/expect

set folder [exec bash -c "ls -td /home/.snapshots/* | head -n 1"];
set otp [exec oathtool --totp -b KEY];
set timeout 120
[ ... ]

你也可以将你的期望脚本设置为DEBUG,以便能够看到它未来失败的原因:

#!/usr/bin/expect -d
相关问题