How can I run anacron in user mode?

12,713

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.
    
    SHELL=/bin/bash
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    
    # 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
    
Share:
12,713

Related videos on Youtube

Glutanimate
Author by

Glutanimate

Medical student, hobbyist programmer. https://www.youtube.com/c/glutanimate

Updated on September 18, 2022

Comments

  • Glutanimate
    Glutanimate over 1 year

    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?

  • Glutanimate
    Glutanimate over 10 years
    Mmh, I am a GUI user myself and the line in .profile has always worked fine for me (Ubuntu 12.04 here).
  • Christoph
    Christoph about 10 years
    Just to confirm, this runs the specified script as the user, so a whoami in the script will give the user name?
  • Sparhawk
    Sparhawk over 8 years
    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.
  • Ciro Santilli OurBigBook.com
    Ciro Santilli OurBigBook.com over 8 years
    @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.
  • Razor
    Razor almost 4 years
    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.
  • stucash
    stucash over 2 years
    @Razor but my .profile entry didn't get me anywhere: anacron didn't run at login. I had to sudo everytime to do this, requiring my password
  • telometto
    telometto over 2 years
    @Glutanimate thank you for this! It has been driving me crazy for a long time.