【发布时间】:2018-04-12 18:35:53
【问题描述】:
我正在使用以下命令设置 cron
crontab -l | { cat; echo -e "#Adding cron task to execute imz script \n0 */1 * * * /usr/local/sbin/generate_imz_report.sh"; } | crontab -
通过 shell 脚本。每次我执行脚本时,它都会为此脚本添加一个新条目
xyx.local: ~ # crontab -l
#Adding cron task to execute imz script
0 */1 * * * /usr/local/sbin/generate_imz_report.sh
#Adding cron task to execute imz script
0 */1 * * * /usr/local/sbin/generate_imz_report.sh
#Adding cron task to execute imz script
0 */1 * * * /usr/local/sbin/generate_imz_report.sh
#Adding cron task to execute imz script
0 */1 * * * /usr/local/sbin/generate_imz_report.sh
#Adding cron task to execute imz script
0 */1 * * * /usr/local/sbin/generate_imz_report.sh
#Adding cron task to execute imz script
0 */1 * * * /usr/local/sbin/generate_imz_report.sh
为了避免这种情况,我尝试了以下方法
grep '#Adding cron task to execute imz script' /etc/crontab || crontab -l | { cat; echo -e "#Adding cron task to execute imz script \n0 */1 * * * /usr/local/sbin/generate_imz_report.sh"; } | crontab -
但这不起作用。如果 shell 脚本中已经存在,如何避免添加 cron 条目?
【问题讨论】: