Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Shell脚本中创建crontab_Shell_Cron - Fatal编程技术网

如何在Shell脚本中创建crontab

如何在Shell脚本中创建crontab,shell,cron,Shell,Cron,我必须自动化我的Crontab脚本,并想在我的Crontab文件中插入一些东西,我想在没有交互式查询的情况下这样做,它应该看起来像命令: 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

我必须自动化我的Crontab脚本,并想在我的Crontab文件中插入一些东西,我想在没有交互式查询的情况下这样做,它应该看起来像命令:

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中应该是这样的:

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

sry对于我糟糕的英语来说

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

crontab -l >/tmp/c1
echo '15 9 * * * /full/path/to/scripts/check_backup_include_list.sh' >>/tmp/c1
crontab /tmp/c1
crontab -l >/tmp/c1
grep -v check_backup_include_list.sh' /tmp/c1 > /tmp/c2
crontab /tmp/c2
如果要删除特定记录,您可以执行以下操作:

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