相关疑难解决方法(0)

如何通过脚本创建crontab

我需要通过运行的脚本添加一个cron作业来设置服务器.我目前正在使用Ubuntu.我可以使用,crontab -e但会打开一个编辑器来编辑当前的crontab.我想以编程方式执行此操作.

有可能这样做吗?

linux shell ubuntu cron crontab

131
推荐指数
9
解决办法
13万
查看次数

将条目插入到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)

bash centos6

8
推荐指数
1
解决办法
4952
查看次数

标签 统计

bash ×1

centos6 ×1

cron ×1

crontab ×1

linux ×1

shell ×1

ubuntu ×1