Relaunching a crontab automatically (UNIX)

Viewed 57

Sometimes there are RAM issues and the crontab doesnt launch properly. So I modified a code that I found while i was researching around to make an automatic relaunch in case the code doesn't run, (because of this and any other issue).

So my objective is, only in case of break, to relaunch it a certain amount of times after a certain amount of minutes using sleep.

EDIT 1: There is enough memory to run the program, and I am sure a relaunch works, because I usually relaunch manually.

EDIT 2: I cannot use alternatives to cron even though I have been told there are better option, which I understand.

I have doubts about the syntax I used and if I input the arguments correctly in the crontab.

This is the code in UNIX:

#!/bin/bash

n=0

until [ "$n" -ge "$2" ]
do
   "$1" && break  
   n=$((n+1)) 
   sleep "$3"m
done

"$1" is my command line, this case: "/home/ad/user/crontab.py"

"$2" is the maximum number of relaunch tryes

"$3" is the time (in minutes) between each relaunch

And this is an example of my crontab:

30 12 * * * /project/common/util/keytab-kinit.sh; /project/common/python3spark2x/python /home/ad/user/test.sh "/home/ad/user/crontab.py" "3" "2"

Executing this, gives no output, so I might be getting wrong somewhere in the code or maybe in the crontab line syntax final inputs. My crontab works perfect in this way:

30 12 * * * /project/common/util/keytab-kinit.sh; /project/common/python3spark2x/python /home/ad/user/crontab.py
0 Answers
Related