Do work every month on a specific day (using anacron?)

I would like to run tasks once a month, say, on the 22nd day of the month, on my laptop running Ubuntu 12.04.

Since this is a laptop, and I cannot always use it every 22nd day of every month, cron not a good option.

Looking into anacron seems to be a limitation. Namely, you can specify a β€œperiod”, but not a specific day of the week or day of the month, as suggested by the anacrontab format:

 # cat /etc/anacrontab period delay job-identifier command 7 15 test.daily /bin/sh /home/myself/backup.sh 

I would like to say that if we are on the 22nd day of the month, and, of course, the laptop is working, start work. If the 22nd is transferred and you did not start the task, run it as soon as I download.

I'm going to do something ugly, like mixing cron and anacron using my own scripts or writing my own bash script using timestamps, possibly rethinking the square wheel in the process.

Any idea for a better action?

Greetings.

+4
source share
1 answer

Run the command daily and the script write down the date the backup was last executed

When it starts, get the current day of the month. If this is the 22nd year, run normally and save the date. If it is> 22, and the last run was in the same month, exit. If it is <22, and the last run was in the previous month (do not forget to consider that it wraps from 12 to 1), exit.

The date should be saved in a file somewhere.

+4
source

Source: https://habr.com/ru/post/1435552/


All Articles