在不使用“ crontab -e”文件的情况下编辑crontab文件时会有什么风险?命令? [英] What is the risk when editing crontab file without the "crontab -e" command?
问题描述
我开发了一个脚本,其中使用 echo
命令向crontab文件添加行,并使用 sed
命令。
I developed a script in which I add lines to the crontab file with echo
command and I remove lines with sed
command.
我不知道这样做的风险,特别是在某些网站上发现我们必须使用
I do not know the risk of that especially that I find in some web site that we have to edit crontab file with
crontab -e
- 不使用
crontab -e
有什么风险? - 是否存在我的编辑不会进行编辑的风险在cron
计划中使用了帐户? - 我应该使用
/etc/init.d/cron
restart重新启动cron吗?
- What is the risk of does not using
crontab -e
? - Are there a risk that my edit will not taken account in the cron schedule?
- Should I restart cron with
/etc/init.d/cron
restart?
推荐答案
不使用 crontab $ c的主要风险$ c>编辑或替换cronfile的原因是直接写入cronfile(包括使用sed这样做)不会锁定文件,因此,同时进行两次编辑可能会带来不可预测的后果,甚至是灾难性的后果。
The main risk to not using crontab
to edit or replace cronfiles is that directly writing to the cronfile (including using sed to do so) does not lock the file, and therefore two simultaneous edits could have unpredictable and even disastrous consequences.
您不必使用 crontab -e
;下列编辑形式是半安全的,即它们不会随机地将两个编辑结合在一起。 (但是它们仍然不安全;编辑可能会被覆盖):
You don't have to use crontab -e
; the following forms of editing are semi-safe, in the sense that they won't randomly combine two edits. (But they are still unsafe; an edit could be overwritten):
添加行:
{ crontab -u user -l; echo "$this"; echo "$this_too"; } | crontab -u user -
要删除行或进行更复杂的编辑:
To delete lines or do more complicated edits:
crontab -u user -l | sed "$my_wonderful_sed_script" | crontab -u user -
无论如何,您无需重新启动 cron
。它将注意到cronfile的修改时间。
In any case, you don't need to restart cron
. It will notice the changed modification time of the cronfile.
这篇关于在不使用“ crontab -e”文件的情况下编辑crontab文件时会有什么风险?命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!