Example: # apt install anacron
-
Make sure your new script is executable
$ chmod u+x my_script.sh
OPTIONAL: If you symlink your script in /usr/local/bin, you can run it anywhere from the terminal
(seerun-parts
for reasons to remove the .sh extension)# ln -s /path/to/my_script.sh /usr/local/bin/my_script_name
-
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 in days # delay: Delay in minutes # job-identifier: Unique name for anacron # command: Command to execute # period delay job-identifier command 1 10 my-script /path/to/my_script.sh # OR 1 10 my-script /usr/local/bin/my_script_name
-
Add the following line to your crontab using
crontab -e
:@hourly /usr/sbin/anacron -s -t $HOME/.anacron/etc/anacrontab -S $HOME/.anacron/spool