Linux crontab FAQ: How do I edit my Unix/Linux crontab file?
I was working with an experienced Linux sysadmin a few days ago, and when we needed to make a change to the root user crontab file, I was really surprised to watch him cd to the root user's cron folder, make changes to the file, then do a
kill -HUP on the crontab process.
Thinking he knew something I didn't know, I asked him why he did all of that work instead of just entering this:
at the command line. After he asked me what that did, we both had a good laugh when I said, "Dude, it automates everything you just did manually."
The Linux crontab documentation is pretty clear about editing the crontab files:
Each user can have their own crontab, and though these are files in /var/spool/, they are not intended to be edited directly.
The documentation further states that the crontab command should be used to edit your crontab file, and you specifically edit the file with the
crontab -e command.
Here's a description of what the
crontab -e command does, taken directly from the crontab man page:
This option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables. After you exit from the editor, the modified crontab will be installed automatically.
I assume that when they say "the modified crontab (file) will be installed automatically", they mean that the new file is put in place of the other file, and then a
-HUP signal is sent to the cron daemon, but I don't know this for fact. I do know that's what I had to do in the old days, so again, I assume that's what they've done to automate this process.
If you've never sent a
HUP signal to a Unix or Linux daemon before, the first thing to know is that
HUP stands for "hangup". While you should be very careful doing this, you can send a
HUP signal to a daemon by using this command:
kill -HUP [pid of the daemon process]
or this equivalent command:
kill -1 [pid of the daemon process]
(That's the number "one" in that last example.)
Again, for daemons that support this signal, the
HUP command typically means "re-read your configuration files, something just changed". I used to use it all the time with the cron and inetd daemons, issuing that command whenever I changed their configuration files.
Before leaving this topic, I just noticed that besides seeing the crontab command options on the crontab man page, you can also see them from the command line by typing something like
crontab -h or
crontab --help. Technically, this doesn't give you the help I expected, but it does give you a crontab usage statement. :)
Here's the output from that usage statement:
usage: crontab [-u user] file crontab [-u user] [ -e | -l | -r ] (default operation is replace, per 1003.2) -e (edit user's crontab) -l (list user's crontab) -r (delete user's crontab) -i (prompt before deleting user's crontab) -s (selinux context)
As you can see, the
crontab -l command lists your crontab, which is the same as cat'ing it out. Personally, I always use the
crontab -e command, but this is one other option I can see using from time to time.
For more information on the Unix and Linux crontab system, here are two links to the crontab man pages (help/support documentation):