Cron tips


On RedHat and family, crontab entries are best made as a separate file under any of the /etc/cron.* directories.

If it's enough that your program runs once every hour, day or month, just place a script or symlink in the respectively cron.hourly, cron.daily or cron.monthly directory.

If you need more control, create a file with a full crontab line in

Logging in crontab entries

A nice way to see whether your crontab entry was correct and was executed properly, is to use logger to write a message to the system log file afterwards. Your crontab entry would then look something like this:

 30 15 * * *     root    thecommand && \
                         logger "thecommand executed successfully"

This can be removed afterwards but it's a help for the first runs.

A different user

To run a crontab as a different user, use the su command. An example where the crontab entry is run as user apache, every five minutes:

 */5 * * * *     root    su -c '/usr/bin/some_command' \
                         -s /bin/sh apache