5

I am unable to configure a cron job to run by placing it in /etc/cron.hourly folder.

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

The file under cron.hourly is :

lrwxrwxrwx 1 root root   40 2010-07-26 14:52 check -> /usr/local/xxxx/check-interface.bash

Permissions on the file :

-rwxr-xr-x 1 root root 1.6K 2010-09-13 11:22 /usr/local/xxxx/check-interface.bash

There seems to be no errors reported in the var/log/cron logfile. No mention of the script is done. :(

6
  • Are you sure crond is running?
    – jamespo
    Commented Mar 28, 2011 at 15:33
  • yep, i restart the daemon after the changes manually.
    – Ricko M
    Commented Mar 28, 2011 at 15:50
  • 1
    chmod +x /usr/local/xxxx
    – forcefsck
    Commented Mar 28, 2011 at 16:51
  • What version of Cron do you have (it's ok if you say what distribution you have)? Some versions have rules for naming files in /etc/cron.*. Is check the actual name of the symlink? Does the script run correctly if you run it manually? Are you sure it's not running and just having no visible effect? Commented Mar 28, 2011 at 18:48
  • Is this a debian system, per chance? Commented Mar 29, 2011 at 15:43

2 Answers 2

3

In order to isolate the problem, move /usr/local/xxxx/check-interface.bash to /etc/cron.hourly/check , and then see if it runs.

If the script does run, then the problem is caused by an ownership/permissions or related issue which is preventing cron from executing scripts at /usr/local/xxxx/*.

If the script does not run, then the problem is most likely with your script itself.

As another sanity check, replace the contents of /usr/local/xxxx/check-interface.bash with something dead simple, like:

date > /tmp/check-interfaces.log 2>&1

And then see if /tmp/check-interfaces.log is actually being populated by your cronjob. If it does work, then the problem must be with your original script.

2
  • 1
    On several distros, run-parts explicitly skips files that have a period in them as they may have been generated by a package update. Maybe that's what he's running up against. Commented Mar 29, 2011 at 11:02
  • Care to elaborate on that please ? I am not sure what you mean by having a period in it. Thanks!
    – Ricko M
    Commented Mar 31, 2011 at 9:22
1

I just want to confirm that as Shadur has mentioned earlier, the issue lies in the fact that by default the "run-parts" application used by cron will run only commands that contain only ASCII letters, _, and -. From the official man page:

   If  neither the --lsbsysinit option nor the --regex option is given then the names must consist entirely of ASCII upper- and lower-case letters, ASCII digits,
   ASCII underscores, and ASCII minus-hyphens.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .