我有一个脚本在提示符下运行良好,但在 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 的某种嵌套级别有关,有这样的事情吗?
此致