Bash – In linux, would it be possible to run a script every day 3 minutes later than the previous day

bashcronlinuxscripting

My first solution to this was to execute date +%Y%m%d%H%M and put that format of numbers into a file, and run the script every minute from cron. Then if the date from the file matches the date command, the script would do something. Then it would update that file for the next day plus 3 minutes. Is there a better way to accomplish this?

The result would be that the script would run the first day at (for example) 4:00am then the second day it would run at 4:03am and the third day it would run at 4:06am. It would execute every minute, but only run (if block) at the correct time.

Is the question and my solution clear?

Best Answer

You can use the at command from within your script (or a wrapper). Give it the time to run the next iteration.

echo '/dir/scriptname' | at 'now + 1443 minutes'

Put that line as near as possible to the beginning of the script to reduce drift.