重命名/ var / spool / cron /中的cron文件意味着cron文件的内容不会再被执行了吗? 或者将/ var / spool / cron /中的所有文件都执行,无论文件的名称如何。
某些系统上/ var / spool / cron(或/ var / spool / cron / crontabs或/ var / spool / cron / tabs)中的文件将以该文件所指定用户的权限运行。 例如,/ var / spool / cron / root将以“root”用户身份运行,/ var / spool / cron / tom_13将以用户“tom_13”的身份运行。
如果一个crontab文件被重命名为另一个有效的用户,它应该以该用户的身份运行。 但是,有两个警告:
crontab命令进行更改,否则某些cron守护程序不会检查/ var / spool / cron以进行更改。 如果您要手动进行更改,则可能需要重新启动cron守护程序才能使其生效。 检查crontab( man 1 crontab )的联机帮助页以查看它是如何工作的。 如果你正在使用Vixie cron(现在大多数Linux发行版似乎都喜欢),你可以做下面的事情来让一个用户的crontab作为一个不同的用户来运行(和重命名文件一样,但是更安全):
crontab -u olduser -l > olduser.cron crontab -u newuser olduser.cron crontab -u olduser -r Cron被收紧到/ etc / crontab中,在那里发生了所有的魔法。 实际上,默认情况下,crontab只有一条类似这样的logging:
-*/15 * * * * root test -x /usr/lib/cron/run-crons && /usr/lib/cron/run-crons >/dev/null 2>&1
如您所见,这将每15分钟执行一次/ usr / lib / cron / run-crons,而run-crons实际上是一个脚本。
简单看一下脚本,你会看到哪些目录应该保存cron脚本:
for CRONDIR in /etc/cron.{hourly,daily,weekly,monthly} ; do
深入挖掘并检查这个脚本是关于什么的,你可以看到, 是的,它会在适当的目录下执行所有的脚本 :
for SCRIPT in $CRONDIR/* ; do test -d $SCRIPT && continue case "$SCRIPT" in .svn) continue ;; *.rpm*) continue ;; *.swap) continue ;; *.bak) continue ;; *.orig) continue ;; \#*) continue ;; *~) continue ;; esac
…除了提到的文件扩展名。 所以你可以简单地添加一个“.bak”添加文件的结尾,以便cron不会执行它。
注意:这篇文章是使用OpenSUSE编写的,其他发行版可能会有所不同
如果你想阻止它运行,一种方法是编辑该用户的crontab并注释掉所有行:
sudo crontab -u username -e
并在每行没有一个的开始处放一个#。
克伦说:
Cron searches /var/spool/cron for crontab files which are named after accounts in /etc/passwd; crontabs found are loaded into memory. Cron also searches for /etc/crontab and the files in the /etc/cron.d direc- tory, which are in a different format (see crontab(5)). Cron then wakes up every minute, examining all stored crontabs, checking each command to see if it should be run in the current minute. When exe- cuting commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists). Additionally, cron checks each minute to see if its spool directoryâs modtime (or the modtime on /etc/crontab) has changed, and if it has, cron will then examine the modtime on all crontabs and reload those which have changed. Thus cron need not be restarted whenever a crontab file is modified. Note that the Crontab(1) command updates the modtime of the spool directory whenever it changes a crontab.
所以,如果我正确地解释这个,重命名为一个未知的用户将做的伎俩..