How can I run anacron in user mode?
12,713
You can set up a separate anacron instance to run in user mode:
Create a
.anacron
folder in your home directory and in it two subfolders,etc
andspool
:mkdir -p ~/.anacron/{etc,spool}
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
Add the following line to your crontab using
crontab -e
:@hourly /usr/sbin/anacron -s -t $HOME/.anacron/etc/anacrontab -S $HOME/.anacron/spool
Related videos on Youtube
Author by
Glutanimate
Medical student, hobbyist programmer. https://www.youtube.com/c/glutanimate
Updated on September 18, 2022Comments
-
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 over 10 yearsMmh, I am a GUI user myself and the line in
.profile
has always worked fine for me (Ubuntu 12.04 here). -
Christoph about 10 yearsJust to confirm, this runs the specified script as the user, so a
whoami
in the script will give the user name? -
Sparhawk over 8 yearsI 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 useranacron
from the usercrontab
. -
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 almost 4 yearsThis 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 over 2 years@Razor but my
.profile
entry didn't get me anywhere:anacron
didn't run at login. I had tosudo
everytime to do this, requiring my password -
telometto over 2 years@Glutanimate thank you for this! It has been driving me crazy for a long time.