Saving Crontab files
Solution 1
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
.
Solution 2
Yes, the cron files must be in /var/spool/cron (or some similar directory, depending on system.) See man 8 cron
.
Solution 3
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.
Phil Braun
Updated on June 04, 2022Comments
-
Phil Braun almost 2 years
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
-
Fred Foo almost 13 yearsBut most likely, you should put them somewhere in
/etc
. -
Seth Robertson almost 13 years@larsmans: The /etc/cron.{daily,hourly,weekly,monthly}/* files are not standard cron files. /etc/cron.d/* files are standard cron files, but are designed for package managers, not humans. Humans should be using the cron API which will put the files where-ever they are supposed to go for your particular system.
-
Fred Foo almost 13 years@Seth: true, but if
/etc/cron.{daily,hourly,weekly,monthly}
are available, they are to be preferred to writing to/var/spool/cron
directly.