【发布时间】:2018-01-23 02:50:12
【问题描述】:
我正在尝试使用 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
【问题讨论】:
-
你为什么用
expect来回答SSH密码提示?你真的不应该那样做。 -
当我发现任何问题时,我会使用 autoexpect 生成脚本,然后对其进行修改以简化。
-
@JohnKugelman 你知道将 borg 备份发送到远程存档的更好方法吗?我非常愿意接受建议。
-
配置好SSH,不会有任何提示。它的提示仅供人类食用。例如,用于连接的私钥上的get rid of the passphrase。文件系统权限应该足以防止密钥被窥探。 (在期望脚本的其他地方列出的密码是没有用的。)