Ubuntu: anacron not working


I have a clean install of Xubuntu 14.04 32-bit, and anacron doesn't seem to be working.

I read that it's better to use a cron job to trim SSDs, and that Ubuntu has a cron job to do that, so I removed discard from /etc/fstab. I wanted to confirm that the cron job was working, so I added an echo command to /etc/cron.weekly/fstrim so that it looks like this:

#!/bin/sh  # call fstrim-all to trim all mounted file systems which support it  echo "Trim started on" $(date) >> /home/dominic/Desktop/Trim_Runs  set -e  # This only runs on Intel and Samsung SSDs by default, as some SSDs with faulty  # firmware may encounter data loss problems when running fstrim under high I/O  # load (e. g.  https://launchpad.net/bugs/1259829). You can append the  # --no-model-check option here to disable the vendor check and run fstrim on  # all SSD drives.  exec fstrim-all  

It runs fine from a terminal, but it never runs as a weekly job. So I moved it to cron.daily, but it never runs from there either. So I moved it to cron.hourly, and it does run every hour. The echo text appears in the file, and the drive light comes on for about two minutes. But cron.hourly does not use anacron.

Here is my crontab file. I have changed some of the times, but it didn't seem to work with the original times that came with Xubuntu either.

# /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 16   * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report      /etc/cron.daily )  47 6    * * 1   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 )  #  

I tested to see if it would run correctly from my user's crontab by putting the following into crontab -e. Then I waited a few minutes until 8:10 pm, but nothing happened.

SHELL=/bin/sh  PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin    10 20   * * *   test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )  

I think it must have the correct syntax for run-parts, because it does run when I move the script into cron.hourly.

It seems that cron is working but anacron is not. So my question is, what can I do to get anacron working?


I got anacron working on my system, as follows:

In /etc/fstab I have some directories moved to tmpfs to avoid writes to the SSD, like this:

tmpfs   /tmp       tmpfs   nodev,nosuid,noatime,mode=1777   0  0  tmpfs   /var/spool tmpfs   nodev,nosuid,noatime,mode=1777   0  0  tmpfs   /var/log   tmpfs   nodev,nosuid,noatime,mode=0755   0  0  

This means that /var/spool/anacron/ does not exist at boot time, and as a result, anacron does not function. The three files in this directory must be preserved across system boots for anacron to work. So I created a directory /usr/local/etc/anacron/, and at boot time I create /var/spool/ and put a symlink in it that points to that directory. Now anacron is working because its three files (cron.daily, cron.weekly, and cron.monthly) are preserved across boots.

Actually, I create a bunch of directories at boot, as described here: How to fix anacron & cups-pdf when you have /var on tempfs but I modified the script so that it doesn't create /var/spool/anacron but instead it creates the symlink mentioned above.

The resulting script looks like this:

#!/bin/bash    # Script to create required directories in tempfs /var/log (that are not otherwise created).  # This script is needed because I have some directories moved to tmpfs in /etc/fstab.  # That means these directories disappear every time I shut down.  # Programs should create them if they do not exist, but some, like anacron, fail to do   so, and then fail to run.  # So I create them here. I don't know where it gets the permissions from, or whether they are right.  # Thanks to http://blog.philippklaus.de/2011/02/ssd-optimizations-on-linux/ for the list below :-)    for dir in apparmor apt ConsoleKit cups dist-upgrade fsck gdm hp installer lightdm news ntpstats samba speech-dispatcher unattended-upgrades upstart; do    if [ ! -d /var/log/$dir ] ; then      mkdir /var/log/$dir    fi  done    # And in /var/spool.  for dir in cups-pdf; do    if [ ! -d /var/spool/$dir ] ; then      mkdir /var/spool/$dir    fi  done    # Create the symlink.  ln -s /usr/local/etc/anacron /var/spool/anacron  

The above script is in my home directory and is run at boot time by a command in /etc/rc.local as described in the linked article.

Maybe the real solution to this problem would be for anacron to store cron.daily, cron.weekly, and cron.monthly in a directory that the user is not likely to move to tmpfs.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »