我需要通过运行的脚本添加一个cron作业来设置服务器.我目前正在使用Ubuntu.我可以使用,crontab -e
但会打开一个编辑器来编辑当前的crontab.我想以编程方式执行此操作.
有可能这样做吗?
将条目插入/ etc/crontab的首选方法是什么,除非它存在,最好使用单行?
这是我希望放入/ etc/crontab的示例条目,除非它已存在于那里.
*/1 * * * * some_user python /mount/share/script.py
Run Code Online (Sandbox Code Playgroud)
我在CentOS 6.6上,到目前为止,我有这个:
if grep "*/1 * * * * some_user python /mount/share/script.py" /etc/crontab; then echo "Entry already in crontab"; else echo "*/1 * * * * some_user python /mount/share/script.py" >> /etc/crontab; fi
Run Code Online (Sandbox Code Playgroud)