首页 > 解决方案 > crontab - 从 bash 脚本创建的编辑

问题描述

我已经在我能想到的所有地方寻找答案,要么我在错误的地方寻找,要么没有人试图从脚本输入 cron 作业。

我有两个 cron 作业(如下),我想检查或设置并从另一个主 bash 脚本运行。主 bash 脚本执行 cron 作业条目(无需手动输入)。它们在这里(调整了路径以便于查看):

if ! crontab -l | grep "@reboot /home/john/this_script.sh > /home/john/this_script_log.txt 2>&1"; then
  (crontab -l ; echo "@reboot /home/john/this_script.sh > /home/john/this_script_log.txt 2>&1") | crontab -

if ! crontab -l | grep "/home/john/that_script.sh > /home/john/that_script_log.txt 2>&1"; then
  (crontab -l ; echo "* * * * * /home/john/that_script.sh > /home/john/that_script_log.txt 2>&1") | crontab -
fi

权限已设置并经过测试。所以他们都跑了。

我不想crontab -e用来调整或输入任何上述 cron 作业(因此管道到crontab -)。据我所知,上面的 if 语句检查 cron 作业是否已经存在,如果不存在,则进入它。

挑战是我错误地在其中一个上走错了路。发现错误后,我尝试对其进行编辑。

我用过crontab -e,没找到。

crontab -l它没有出现。

有谁知道如何查找和编辑上面输入的任何脚本(crontab -)crontabs?

谢谢你

标签: bashcron

解决方案


推荐阅读