Will renaming a cron file in /var/spool/cron/ mean that the contents of the cron file will not be executed anymore? Or will all files in /var/spool/cron/ be executed, no matter the name of the file.
4 Answers
Files in /var/spool/cron (or /var/spool/cron/crontabs or /var/spool/cron/tabs on some systems) will be run with the permissions of the user for whom the file is named. For instance, /var/spool/cron/root will run as user "root" and /var/spool/cron/tom_13 will run as user "tom_13".
If a crontab file is renamed to another valid user, it should run as that user. However, there are two caveats:
- If you rename a crontab to a filename that does not correspond to a valid user, I don't know what the expected behavior is. It might run as root, it might run as the user owning the file, or might not run at all.
- Some cron daemons do not check /var/spool/cron for changes unless you make those changes with the
crontab
command. If you are going to make changes manually, you may need to restart your cron daemon for them to take effect.
Check the manpage for crontab (man 1 crontab
) to see how it works. If you're using Vixie cron (which most Linux distributions seem to favor these days), you could do the following to make one user's crontab run as a different user (same effect as renaming the file, but safer):
- Save the old user's crontab to a file:
crontab -u olduser -l > olduser.cron
- Import it into the new user's crontab:
crontab -u newuser olduser.cron
- Delete the old user's crontab:
crontab -u olduser -r

- 6,835
- 24
- 27
Cron is tightened to /etc/crontab, where all the magic happens. Actually, by default crontab has only one record similar to this:
-*/15 * * * * root test -x /usr/lib/cron/run-crons && /usr/lib/cron/run-crons >/dev/null 2>&1
As you see, this will execute /usr/lib/cron/run-crons every 15 minutes and run-crons in fact is a script.
Taking a brief look at the script you will see what directories should hold cron scripts:
for CRONDIR in /etc/cron.{hourly,daily,weekly,monthly} ; do
Digging deeper and checking what this script is about you can see that yes, it will execute all the scripts in appropriate directories:
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
... except mentioned file extensions. So you can simply add a ".bak" add the end of the file so cron will not execute it.
NOTE: This post is written using OpenSUSE, and things can vary for other distros

- 1,621
- 1
- 14
- 20
-
2Entries in /etc/crontab and /etc/cron.* are installed and run independently of the per-user crontabs in /var/spool/cron that Tom_13 is asking about. – James Sneeringer Oct 06 '09 at 16:07
-
If you want to prevent it from running, one way would be to edit the crontab for that user and comment out all the lines:
sudo crontab -u username -e
and put a # at the beginning of each line that doesn't have one.

- 62,149
- 16
- 116
- 151
The man cron says the following:
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.
So if I interpret this correctly, a rename to an unexisting user will do the trick..

- 51
- 2
- 5
-
My `man cron` says "Note that crontabs in this directory should not be accessed directly - the crontab command should be used to access and update them." – Dennis Williamson Oct 07 '09 at 18:08