【问题标题】:Here document not executed in subshell in crontab此处文档未在 crontab 的子外壳中执行
【发布时间】:2013-01-11 10:17:41
【问题描述】:

我的脚本在提示符下运行良好,但在 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

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

最好的问候

【问题讨论】:

  • 尝试删除&lt;&lt;之后的空格?
  • @tripleee 我只是尝试删除空间,它并没有改变问题。 crontab KO,提示确定。

标签: bash cron sftp heredoc


【解决方案1】:

好的,问题解决了:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-29
    • 2023-01-22
    • 2016-04-29
    • 2023-03-13
    • 2013-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多