7

This question already has an answer here:

What is the difference between crontab -e and nano /etc/crontab? Do they point to the same thing?

marked as duplicate by Melebius, Charles Green, user68186, Pilot6, Elder Geek Mar 5 at 21:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

12

The crontab -e command will edit the crontab for your current user. This means that you do not need to include the username in the crontab line. Each user's crontab is stored in /var/spool/cron/crontabs, under the user's name.

The format of a user specific crontab is:

# m h  dom mon dow  command
*   *   *   *   *   some_command

The crontab -e command will use whichever editor is set in your user's $EDITOR environment variable, which controls your default text editor for a variety of tasks. If that isn't set the first time you use the crontab command you'll be prompted to choose from a selection of available editors, nano is one of the choices on this list.

Editing /etc/crontab requires that you include a username that's running the command after the time setting part of the line.

The format of /etc/crontab is:

# m h dom mon dow user      command
*   *  *   *   *  someuser  some_command
  • 4
    doesn't crontab -e also do a syntax check ? AFAIK, that does not happen if you edit /etc/crontab – Robert Riedl Feb 21 at 12:11
  • I think you're right. I wasn't sure though so didn't add it to the answer. I also think the crontab command is more highly recommended for general use, but again wanted to check before adding to the answer. – Arronical Feb 21 at 12:45
  • it also seems to be undocumented and not catch all sytnax errors – Robert Riedl Feb 21 at 12:50
  • 2
    Another diff between crontab -e and nano /etc/crontab is that using the crontab command will use the current $EDITOR whereas the latter is using a specific editor (nano). The way the question was wondered suggested to me that OP didn't know this difference. – Scribblemacher Feb 21 at 13:13
  • 1
    also, crontab -ewill install the new crontab on save, while editing /etc/crontabwill not. cron does reload it on its own, eventually – Robert Riedl Feb 21 at 18:21
0

The traditional system cron list is at /etc/crontab

The user crontabs are usually located at /var/spool/cron/crontabs/$USER.

Doing a 'crontab -e' automatically invokes the users editor and performs a basic validity/syntax check when you attempt to exit.

Any jobs scheduled using the user crontab are run under the users login id whereas the the system /etc/crontab has the capability to schedule jobs under any system userid listed in /etc/passwd.

If you want to play with fire, you can directly edit (vi/vim/nano/mcedit/...) your user crontab, bypassing any syntax check, by using for instance, "nano /var/spool/cron/crontabs/your-login-id" [ Or any userid if you are root or use sudo ]

For more detailed info, you might want to peruse the cron man pages ( 'man cron' )

Not the answer you're looking for? Browse other questions tagged or ask your own question.