I would like to set up a scheduled task via anacron but I would like to do so in user mode. How can I achieve this?


You can set up a separate anacron instance to run in user mode:

  1. Create a .anacron folder in your home directory and in it two subfolders, etc and spool:

    mkdir -p ~/.anacron/{etc,spool}
  2. Create a new file ~/.anacron/etc/anacrontab with contents similar to the following:

    # /etc/anacrontab: configuration file for anacron
    # See anacron(8) and anacrontab(5) for details.
    # period  delay  job-identifier  command
    1         10     testjob         test.sh
  3. Add the following line to your crontab using crontab -e:

    @hourly /usr/sbin/anacron -s -t $HOME/.anacron/etc/anacrontab -S $HOME/.anacron/spool
  • 3
    I think you need to run anacron periodically; it seems to run once then quit. The system's anacron is called once every hour. I suppose a similar strategy would work here, i.e. call the user anacron from the user crontab.
    – Sparhawk
    Nov 3 '15 at 3:00
  • 1
    @Sparhawk agreed, in particular Ubuntu 15.10 anacron uses both /etc/apm/event.d/anacron and /etc/init/anacron.conf to take care of restarts. Dec 9 '15 at 21:53
  • 1
    You need to run anacron hourly with a cron job, e.g. 01 * * * * /usr/sbin/anacron -t /home/user/.anacron/etc/anacrontab -S /home/user/.anacron/spool Aug 17 '16 at 5:15
  • 1
    This won't work if the user has an encrypted home directory. I've replaced that last crontab -e command with an entry in my ~/.profile instead.
    – Razor
    Jul 24 '20 at 5:05
  • 1
    @Glutanimate thank you for this! It has been driving me crazy for a long time.
    – telometto
    Jan 14 at 12:44

This worked for me (thanks), but I didn't use the last step given in the answer:

Then add the following line to your ~/.profile:

I'm using Ubuntu Studio 12.10 Quantal and in my case instead of that last step I put that one liner here: “Applications Menu” → “Settings” → “Settings Manager” then in the Settings Manager under “Session and Startup” then the “Application Autostart” tab.

This is for those of us that are GUI users, because ~/.profile is only sourced by bash when it starts a log-in interactive shell (even ~/bashrc is not so useful since that is only sourced when bash is starting an interactive shell).

  • Mmh, I am a GUI user myself and the line in .profile has always worked fine for me (Ubuntu 12.04 here). Sep 12 '13 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.