How do I run a program only once per day, while accounting for variable uptime and possible failure of program?

I require to run a command as soon as, yet just as soon as, daily, till it does well.

Continual uptime can not be anticipated, and also program success can not be assured.

This program calls for network accessibility, yet not every single time I start my computer system with network accessibility.

My program will certainly exit with, e.g - 1 unless it do well (which returns 0 ).

2022-06-07 14:39:55
Source Share
Answers: 2

Use a shell to give this. As an example, create a manuscript with something like the following:

# Check to see if this is already running from some other day
mkdir /tmp/lock || exit 1
while ! command-to-execute-until-succeed; do
    # Wait 30 seconds between successive runs of the command
    sleep 30
rmdir /tmp/lock

After that, factor cron to the manuscript.

2022-06-07 15:07:52

I assume the most convenient means to do this would certainly be for your program to look for a documents is presence prior to making the effort, and also to create that documents once it implements efficiently.

If you can not change the program to do so, make use of the cronjob itself. Something along the lines of:

test -e /path/to/tempfile || ( /path/to/program && touch -a /path/to/tempfile )

Because of the means unix reviews problem checks, as soon as the left side of the || problem reviews to true, the whole expression holds true and also the appropriate side is never ever reviewed - - IE, the program isn't called.

After that inside the parens, && calls for both sides to review to real, so if /path/to/program leaves with a nonzero return code, there is no factor in reviewing the declaration on the appropriate - - the expression currently reviews to incorrect - - and also /path/to/tempfile is never ever developed.

2022-06-07 15:07:36