8

I'd like to use anacron for a weekly job on Ubuntu 13.04.

Here's my /etc/crontab:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 5   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

here's my /etc/anacrontab:

# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
HOME=/root
LOGNAME=root

# These replace cron's entries
1   5   cron.daily  run-parts --report /etc/cron.daily
7   10  cron.weekly run-parts --report /etc/cron.weekly
@monthly    15  cron.monthly    run-parts --report /etc/cron.monthly

Here's my /etc/cron.weekly/0anacron:

#!/bin/sh
#
# anacron's cron script
#
# This script updates anacron time stamps. It is called through run-parts
# either by anacron itself or by cron.
#
# The script is called "0anacron" to assure that it will be executed
# _before_ all other scripts.

test -x /usr/sbin/anacron || exit 0
anacron -u cron.weekly

And finally here's the script I put in /etc/cron.weekly/ :

#!/bin/sh
curlftpfs -o allow_other,skip_pasv_ip mauro-casa.no-ip.org:21001/Volume_1/Foto/Marta/ /home/mauro/Pubblici/Marta_NAS/
sleep 5
rsync -rlt --update --ignore-existing --size-only --exclude=.picasaoriginals/* --exclude=.picasaoriginals --exclude=.directory --exclude=.dropbox --exclude=picasa.ini --temp-dir=/home/mauro/.rsync-temp/ /home/mauro/Dropbox/Marta/ /home/mauro/Pubblici/Marta_NAS/
umount -l /home/mauro/Pubblici/Marta_NAS/

The script is obviously chmoded +x, and it works perfectly if executed manually (with sudo).

EDIT #1

As requested, here's output of

cat /var/log/cron.log | grep "Oct 13"

Oct 13 08:29:05 mauro-alienware anacron[1315]: Anacron 2.3 started on 2013-10-13
Oct 13 08:29:05 mauro-alienware cron[1266]: (CRON) INFO (pidfile fd = 3)
Oct 13 08:29:05 mauro-alienware cron[1403]: (CRON) STARTUP (fork ok)
Oct 13 08:29:05 mauro-alienware cron[1403]: (CRON) INFO (Running @reboot jobs)
Oct 13 08:29:06 mauro-alienware anacron[1315]: Will run job `cron.daily' in 5 min.
Oct 13 08:29:06 mauro-alienware anacron[1315]: Jobs will be executed sequentially
Oct 13 08:34:05 mauro-alienware anacron[1315]: Job `cron.daily' started
Oct 13 08:34:05 mauro-alienware anacron[1651]: Updated timestamp for job `cron.daily' to 2013-10-13

It seems no logs for cron.weekly is showed.

Instead, here's an extract from cat /var/log/cron.log.1 | grep "Oct 11" output:

Oct 11 06:47:01 mauro-alienware CRON[12553]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ))
Oct 11 06:59:11 mauro-alienware anacron[5125]: Anacron 2.3 started on 2013-10-11
Oct 11 06:59:11 mauro-alienware anacron[5125]: Normal exit (0 jobs run)
Oct 11 07:45:54 mauro-alienware anacron[5444]: Anacron 2.3 started on 2013-10-11
Oct 11 07:45:54 mauro-alienware anacron[5444]: Normal exit (0 jobs run)
Oct 11 07:46:39 mauro-alienware CRON[9156]: (root) CMD (start -q anacron || :)
Oct 11 07:46:39 mauro-alienware anacron[9159]: Anacron 2.3 started on 2013-10-11
Oct 11 07:46:39 mauro-alienware anacron[9159]: Normal exit (0 jobs run)
Oct 11 08:46:31 mauro-alienware cron[1249]: (CRON) INFO (pidfile fd = 3)
Oct 11 08:46:31 mauro-alienware cron[1308]: (CRON) STARTUP (fork ok)
Oct 11 08:46:31 mauro-alienware cron[1308]: (CRON) INFO (Running @reboot jobs)
Oct 11 08:46:31 mauro-alienware anacron[1303]: Anacron 2.3 started on 2013-10-11
Oct 11 08:46:31 mauro-alienware anacron[1303]: Normal exit (0 jobs run)
Oct 11 08:46:35 mauro-alienware anacron[1839]: Anacron 2.3 started on 2013-10-11
Oct 11 08:46:35 mauro-alienware anacron[1839]: Normal exit (0 jobs run)
Oct 11 08:46:37 mauro-alienware anacron[4700]: Anacron 2.3 started on 2013-10-11
Oct 11 08:46:37 mauro-alienware anacron[4700]: Normal exit (0 jobs run)
9
  • don't see any cron.hourly log reports from your output, please, provide full logs somewhere. Oct 14, 2013 at 14:33
  • I need weekly jobs to be executed, not hourly!
    – jasmines
    Oct 14, 2013 at 15:01
  • they are not written to logs, but exists in crontab, so you missing something or your cron does not work at all Oct 14, 2013 at 15:03
  • here you are with pastebin complete cron.log: pastebin.com/gfeGTP4T
    – jasmines
    Oct 14, 2013 at 15:06
  • and here you are with complete cron.log.1: pastebin.com/9TBQWNbF
    – jasmines
    Oct 14, 2013 at 15:07

3 Answers 3

18

You didn't post the actual name of the script you are trying tun run, but chances are it contains a dot ('.'), like if it is ending in '.sh'.

run-parts will not run scripts which contain anything else but alphanumerical characters or hyphens. Remove the dot and you are fine.

1
9

When does anacron run

Usually anacron does not run as a daemon. On Debian based systems it runs with classic cron at /etc/cron.d/anacron. It also starts after a system startup, resume from sleep and changing power management state.

You can check the date when anacron job was last run with sudo cat /var/spool/anacron/cron.weekly.

5
  • 20131013... It seems to be running correctly, isn't it?
    – jasmines
    Oct 14, 2013 at 9:48
  • yes, it's looks like updating by 0anacron working, now check /var/log/syslog for Oct 10 for anacron output. You should find something like anacron[26500]: Job ``cron.weekly' terminated anacron[26500]: Normal exit (2 jobs run) Oct 14, 2013 at 9:57
  • why are you asking Oct 10 and not Oct 13?
    – jasmines
    Oct 14, 2013 at 10:51
  • @jasmines it's just typo, of cause you should check Oct 13 Oct 14, 2013 at 12:11
  • Find some output in my last edit.
    – jasmines
    Oct 14, 2013 at 12:26
1
cat /etc/cron.d/anacron

will show you the hour and day when anachron will run, for example:

# /etc/cron.d/anacron: crontab entries for the anacron package

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

30 7    * * *   root    start -q anacron || :

shows you it will run every morning at 7:30 am but only once a week. It checks the date written in

sudo cat /var/spool/anacron/cron.weekly

(If the date is older, It will start and update the date in that file)

1
  • cat: /etc/cron.d/anacron: No such file or directory
    – Asalle
    Jun 6, 2020 at 8:06

You must log in to answer this question.

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