2

I have a weekly cron job set up to run every Saturday morning at 00:01 AM. The anacron.weekly entry in the crontab is set to run at Saturdays at 00:01 AM crontab entry is:

1 0 * * 6 root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )

The anacrontab has a a weekly entry set up as:

7 10 cron.weekly run-parts --report /etc/cron.weekly

The script is contained in the /etc/cron.weekly directory, owned by root, with execute permissions

The problem is that the job does not run when I am NOT logged in as root, but as soon as I log in as root, the cron job will run perfectly (after the 10 min anacron delay) and do exactly what it is supposed to do.

The job does exhibit the desired behavior of once it runs, it won't run again until after the next weekly job is supposed to run, but then only after I log in. i.e. If I log in on Friday night it won't run but if I log in on Saturday night it will and then wont' run again until after 00:01 the next Saturday.

My filesystem nor my home directory are encrypted. The job is owned by root and only runs when I log in as root. Once the job runs, it is logged in the /var/log/syslog, and the /var/spool/anacron/cron.weekly file is set to the date the job ran. All log files created by the job are created and show a successful completion.

I have verified that the server is up at the time the job is supposed to run.

Any ideas?

4
  • what is the name of the script? This really sounds fishy :-(
    – Rinzwind
    Feb 25, 2015 at 6:34
  • The script is a script I created, mediaback no extensions. It creates archives of all my movies, pictures and music. The script doesn't seem to be the problem since it runs perfectly after I log in. Here is the listing from the /etc/cron.weekly directory.
    – jo or
    Feb 25, 2015 at 12:49
  • Got caught by the edit timer:@Rinzwind Thanks for the reply, the script is a script I created, mediaback no extensions. It creates archives of all my movies, pictures and music. The script doesn't seem to be the problem since it runs perfectly after I log in. Here is the listing from the /etc/cron.weekly directory. -rw-r--r-- 1 root root 102 Feb 9 2013 .placeholder >-rwxr-xr-x 1 root root 312 Feb 19 2014 0anacron >-rwxr-xr-x 1 root root 4293 Feb 21 10:24 mediaback
    – jo or
    Feb 25, 2015 at 12:56
  • Are you logging in as root, or logging in as user and becoming root? Try this cron job both when you are logged in and not: (date;mount;pwd;echo $PATH;id) >>/tmp/logfile and check for differences.
    – waltinator
    Mar 8, 2015 at 17:56

1 Answer 1

0

Make sure that you are actually running anacron regularly and not just when logged in as root. The line you posted from your crontab tests if anacron is executable and if it isn't will run your weekly scripts Saturdays at 00:01 AM—in particular, it does not run anacron even if present and executable.

anacron needs regular opportunities to run, and each time will check and run any tasks that have come due. On my system (Arch, not Ubuntu), cron runs anacron hourly via a 0anacron script in /etc/cron.hourly.

You must log in to answer this question.

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