开发者

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: Cre开发者_如何学运维ating more permanent crontab files


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜