如何使用bash脚本将crontab作业添加到crontab? [英] How to add a crontab job to crontab using a bash script?
本文介绍了如何使用bash脚本将crontab作业添加到crontab?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了以下命令,并且crontab停止运行任何作业:
echo "@reboot /bin/echo 'test' > /home/user/test.sh"| crontab -
I tried the below command and crontab stopped running any jobs:
echo "@reboot /bin/echo 'test' > /home/user/test.sh"| crontab -
在Linux中编写脚本以将作业添加到crontab的正确方法是什么?
What is the correct way to script adding a job to crontab in linux?
推荐答案
我建议您阅读 Cron和Crontab的用法和示例.
您可以运行以下命令:
➜ ( printf -- '0 4 8-14 * * test $(date +\%u) -eq 7 && echo "2nd Sunday"' ) | crontab
➜ crontab -l
0 4 8-14 * * test $(date +\0) -eq 7 && echo "2nd Sunday"
或
#!/bin/bash
cronjob="* * * * * /path/to/command"
(crontab -u userhere -l; echo "$cronjob" ) | crontab -u userhere -
希望这会有所帮助.
这篇关于如何使用bash脚本将crontab作业添加到crontab?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文