Take the tour ×

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.

share|improve this question
You might want to specify what OS this is on, and if Linux, which distro. –  Some Guy Oct 6 '09 at 15:47
@Some Guy: The tag says "redhat" –  Dennis Williamson Oct 6 '09 at 16:20
add comment

4 Answers

The man cron says the following:

   wakes up every minute, examining all stored  crontabs,  checking  each
   if such exists).

   Additionally, cron checks each minute to see if its spool  directoryâs
   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..

share|improve this answer
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 7 '09 at 18:08
add comment

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.

share|improve this answer
add comment

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:

  1. 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.
  2. 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):

  1. Save the old user's crontab to a file: crontab -u olduser -l > olduser.cron
  2. Import it into the new user's crontab: crontab -u newuser olduser.cron
  3. Delete the old user's crontab: crontab -u olduser -r
share|improve this answer
add comment

Cron is tightened to /etc/crontab, where all the magic happens. Actually, by default crontab has only one record similar to this:


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 ;;

... 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

share|improve this answer
Entries 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 6 '09 at 16:07
-1 for not answering the question –  asdmin Oct 6 '09 at 16:36
add comment

Your Answer


