如何在Shell脚本中创建crontab [英] How can I create a crontab in a Shell script

查看:664
本文介绍了如何在Shell脚本中创建crontab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使Crontab脚本自动化,并想在Crontab文件中插入一些内容,我想在没有交互式查询的情况下执行此操作,并且它应类似于命令:

I have to automate my Crontab script and would like to insert some things in my Crontab file, I want to do that without interactive query and it should look like command:

crontab_admin.sh -add -s "15 9 * * *" -c "check_backup_include_list.sh" -u "USERNAME" -t "CRQ000000000000"

crontab_admin.sh -remove -s "15 9 * * *" -c "check_backup_include_list.sh" -u "USERNAME" -t "CRQ000000000000"

,然后在crontab中看起来应该像这样:

and it should look like this in crontab afterwards:

15 9 * * * $HOME/scripts/check_backup_include_list.sh

抱歉我的英语不好

推荐答案

直接对cron文件进行操作是不明智的。但是您可以使用以下脚本添加记录:

Its not wise to operate directly with cron file. But you can add record with script like this:

crontab -l >/tmp/c1
echo '15 9 * * * /full/path/to/scripts/check_backup_include_list.sh' >>/tmp/c1
crontab /tmp/c1

如果要删除特定记录,则可以使用类似这样的操作:

If you want to remove particular record you can do for example with something like this:

crontab -l >/tmp/c1
grep -v check_backup_include_list.sh' /tmp/c1 > /tmp/c2
crontab /tmp/c2

这篇关于如何在Shell脚本中创建crontab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆