Skip to content

Instantly share code, notes, and snippets.

@DallasO
Last active January 15, 2020 17:55
Show Gist options
  • Save DallasO/a0a878489a529c6f2fcd2f9b848d886f to your computer and use it in GitHub Desktop.
Save DallasO/a0a878489a529c6f2fcd2f9b848d886f to your computer and use it in GitHub Desktop.
Steps to add a user level anacron

Installing Anacron for User scripts

Make sure anacron is installed

Example: # apt install anacron

Set up script to be ran by anacron

  1. 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
    (see run-parts for reasons to remove the .sh extension)

    # ln -s /path/to/my_script.sh /usr/local/bin/my_script_name
    
  2. Create a .anacron folder in your home directory and in it two subfolders, etc and spool:

    $ mkdir -p ~/.anacron/{etc,spool}
    
  3. 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
  4. Add the following line to your crontab using crontab -e:

     @hourly /usr/sbin/anacron -s -t $HOME/.anacron/etc/anacrontab -S $HOME/.anacron/spool
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment