User Tools

Site Tools


anacron

If you want to send us your comments, please do so. Thanks
More on comments


Anacron

Run a command

  • daily
  • weekly
  • monthly

if the computer is running :-)

Main rule

Always put the code in a script
Start the script with

#! /bin/bash

Then call the script from anacron. If you do not use a script you can get something like

/bin/sh: 1: [[: not found

in the case you used an [[ statement for example

Servers

On servers do not user anacron, use cron

Alternative

Put scripts in a file in /etc/cron.daily, /etc/cron.weekly or /etc/cron.monthly

  • They are executed after the anacrontab file is processed
  • Scripts in these directories are processed in alphanumerical order. Scripts starting with a number first

Restart service

systemctl restart anacron.service

Configuration files

FileRemark
/home/user/.local/anacrontabFor user specific entries
/etc/anacrontabPut the non user entries in this file
/etc/cron.d/anacron
/etc/default/anacron
/etc/init.d/anacron

Environment

Syntax: VAR=VALUE

CommandRemark
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOME=/rootOr used in crontab only?
LOGNAME=rootUsed in the From: field the e-mail. Username, may not be changed. Or used in crontab only?
MAILTO=userUser to whom the output of anacron has to be mailed
START_HOURS_RANGE=10-12In this time frame jobs are started. If missed they are skipped for that day
RANDOM_DELAY=delaytime0: off. Other value: Add a delay of 0 to delaytime minutes to the delay time (see commands section)

Comments

  • Blank lines
  • White-space only lines
  • White-space followed by a '#' followed by a comment

Commands

OptionExplanation
perioddays
delayminutes
job-identifierMake up yourself. “ ” (space) and “/” are not allowed
commandAny shell command or script. Field separation with blank spaces or tabs
SyntaxRemark
period delay job-identifier commandperiod is in days
monthly delay job-identifier commanddaily nor weekly are possible. Use the previous syntax with a period of 1 or 7

Command continuation

Place a '\' and continue the command on the next line

  4 10 backupSomething cp /home \
                          /backup

Options - --

Short, -, nor long, --, options are allowed. There will be an error message: “/bin/sh: 0: Illegal option -”, (long --)
Solution: write a script and have anacron run it

Examples

 # Comment
4 10 backupSomething cp /home /backup
monthly 20 backupSomething cp /home /backup
 
 # An other comment

Test

CommandExplanation
anacron -TTest the anacrontab file
anacron -nfRun all commands now regardless the timestamp

Last run date

Check the date when an anacron job has last run in /var/spool/anacron/jobname. The format is yyyymmdd (may depend on the locale setting)

Run in user mode

anacron needs root privileges to run. You can run it in user mode. Do

  • mkdir -p /home/user/.local/spool/anacron
  • crontab -e and add:
@reboot /usr/sbin/anacron -s -t $HOME/.local/anacrontab -S $HOME/.local/spool/anacron 
@hourly /usr/sbin/anacron -s -t $HOME/.local/anacrontab -S $HOME/.local/spool/anacron 
@daily /usr/sbin/anacron -s -t $HOME/.local/anacrontab -S $HOME/.local/spool/anacron 

@hourly runs at every full hour: [0-24]:00
@daily runs very day at midnight: 0:00

man pages

  • man 8 anacron
  • man 5 anacorntab
  • man run-parts (run scripts or programs in a directory)
  • man cron

Why would anacron not be running


Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2022 Webevaluation.nl and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
anacron.txt · Last modified: 16-06-2021 03:11 by wim