linux - 在 CronTab 中引用 Bin

标签 linux bash cron cron-task

当我运行以下每个命令时,它们都成功运行。但是当我将它放入下面的 Cron 作业中时,它不会运行。请帮忙:

35 14 20 6 2 rm //var/opt/dsdw-raw/dbo.mb_membership/LOAD00000001.csv && sleep 2 && \
aws s3 sync s3://ams-inbound-data-strategy/dbo.mb_membership/ //var/opt/dsdw-raw/dbo.mb_membership/ \
--exclude '*.dfm' && sleep 1 && /bin/sh /home/ec2-user/skippedrec.sh && \
sleep 10 export PATH=$PATH:/var/opt/mlcp/bin && sleep 1 && mlcp.sh import \
 -options_file /var/opt/dsdw-opt/load-ams-mb_membership.opt

最佳答案

Cronjobs 必须出现在 crontab 中的一行上。它们不能用反斜杠继续到多行。

如果您的 cronjob 足够复杂,以至于您觉得需要使用反斜杠,那么您可能应该将其移动到单独的 shell 脚本中,然后从 cronjob 执行该脚本(例如,35 14 20 6 2/bin/sh/path/to/script.sh)。这也将使您可以测试脚本而无需从 cron 运行它!

关于linux - 在 CronTab 中引用 Bin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44661880/

相关文章:

linux - 如何对以减号开头且包含空格的文件执行 sh 脚本?

php - Linux 的 cron 是异步的还是同步的?

linux - 安排 Cron 跳过每个月的第一个星期六

java - quartz 作业运行

linux - Bash shell 脚本 : Concating lines that do not end in ^M

linux - Bash - 使用 socat 的代理服务器

PHP 和 cURL : same code but unable to fetch content on existing server conf

linux - 为什么 find 在反引号内产生一个空的新行?

Linux 去除串口多余字符

bash - 使用 bash 查找包含字符串的第一个文件夹名称