Phil Braun
Phil Braun

Reputation: 591

Saving Crontab files

A simple question about Crontab, does it matter where I save crontab files? (creating the time-dependent jobs using crontab -e) or can they be read from any directory?

I ask because it seemed that my crontab file got deleted because when I used the crontab -l it didn't return anything. However, I think that is because I saved it as a temporary file: Creating more permanent crontab files

Upvotes: 4

Views: 15552

Answers (3)

Jonathan Leffler
Jonathan Leffler

Reputation: 754020

Normally, you use crontab to create the file, and it stores it in the correct place for your machine.

$ crontab < $HOME/etc/crontab

Then you use crontab -l to list it.

$ crontab -l
#   @(#)$Id: crontab,v 4.2 2007/09/17 02:41:00 jleffler Exp $
#   Crontab file for Home Directory for Jonathan Leffler (JL)
#-----------------------------------------------------------------------------
#Min     Hour    Day     Month   Weekday Command
#-----------------------------------------------------------------------------
0        *       *       *       *       /usr/bin/ksh /work4/jleffler/bin/Cron/hourly
1        1       *       *       *       /usr/bin/ksh /work4/jleffler/bin/Cron/daily
23       1       *       *       1-5     /usr/bin/ksh /work4/jleffler/bin/Cron/weekday
2        3       *       *       0       /usr/bin/ksh /work4/jleffler/bin/Cron/weekly
21       3       1       *       *       /usr/bin/ksh /work4/jleffler/bin/Cron/monthly
$

Where I keep my original is immaterial (but it is under source control in $HOME/etc as it happens). The system has its own copy of the file where it needs it.

If you try placing the files manually, you will get bitten. It might work, but then again, it might not (and it might change in the future). I wouldn't play the risky game of using other than the kosher command to store crontab files for use by crontab.

Upvotes: 7

Seth Robertson
Seth Robertson

Reputation: 31461

If you use the cron api (crontab -e or crontab filename for most systems) your cron jobs will be saved in the proper place permanently, whether you log out or not.

The only way this would not happen is if you were administratively prevented from using cron (not uncommon).

Remember the format of the file you are creating is in man 5 crontab format. It is NOT your shell script.

Upvotes: 1

Charlie Martin
Charlie Martin

Reputation: 112366

Yes, the cron files must be in /var/spool/cron (or some similar directory, depending on system.) See man 8 cron.

Upvotes: 3

Related Questions