0

我有一个脚本在提示符下运行良好,但在 crontab 中运行良好。唯一被破坏的是脚本的子shell中忽略的here文档。该脚本使用 psftp。这是代码:

/home/batch/myscript.sh:

(
cd /home/downloaded/csv/
psftp -pw passw0rd -P 1234 user@someftp.com << EOF
cd outgoing
mget *.csv
EOF
) | tee /home/batch/logs/mylog.log | mail -s "Mail subject" "me@mycompany.com"

crontab -e:

45 10 * * * /bin/sh /home/batch/myscript.sh

好的 - 从提示启动时的邮件:

Remote working directory is /
psftp> Remote directory is now /outgoing
psftp> *.csv: nothing matched
psftp> quit

KO - 从 crontab 启动时的邮件:

Remote working directory is /
psftp> quit

谷歌没有提供很多帮助。我尝试了几种 EOF 语法,因为这似乎是这里文档的常见问题,但我认为它不是来自这个。它可能与 crontab 的某种嵌套级别有关,有这样的事情吗?

此致

4

1 回答 1

1

好了,问题解决了:

用于执行脚本的用户 crontab 是不同的。发生的事情是 sftp 的密钥没有为该用户注册。这会导致提示要求注册密钥,我的脚本没有回答。

我以它使用的用户身份连接,psftp'd 并注册了密钥。

于 2013-01-11T12:06:38.463 回答