1

CentOS 5.x

I noticed that someone (presumably another admin) added an entry directly to the bottom of /etc/crontab so it reads like:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
00 3 * * 0 root foocommand

Assuming that I indeed want the command to run as root, are there consequences to adding scheduled tasks this way? I'm more accustomed to using crontab -e to add/edit scheduled tasks.

Braiam
  • 35,991
Mike B
  • 8,900

1 Answers1

2

From running the command in the crontab file there is no difference. At least Vixie cron (as on CentOS) checks every minute if the spool directory's modification time or that of /etc/crontab has changed.

However if you edit via crontab -e, and write the crontab will be checked for glaring errors. E.g if the last line of your crontab is * * * * you will get the message:

crontab: installing new crontab
"/tmp/crontab.HbT2Sa/crontab":27: bad day-of-week
errors in crontab file, can't install
Do you want to retry the same edit? (y/n) 

(at least if that last line is line 27).

Such a checking mechanism is of course not in place if you just add lines to the crontab file (either /etc/crontab or those in /var/spool/cron/).

Anthon
  • 79,293
  • Sorry - I'm still a bit confused. Why is the format different between /var/spool/cron/foo and /etc/crontab. Are two completely different cron tools involved? – Mike B Nov 06 '14 at 17:02
  • @MikeB /etc/crontab is executed by root, and you need to specify a username as who you run the command (6th field). The others are user crontabs, they always run as the user the crontab belongs to, and don't need that field (it's implicit). – Anthon Nov 06 '14 at 17:04