I have main.ksh which will call various scripts inside and let us assume script1.ksh,script2.ksh,script3.ksh,script4.ksh.
Main.ksh
Some Unix commands1
script1.ksh
Some Unix commands2
script2.ksh
Some Unix commands3
script3.ksh
Some Unix commands4
script4.ksh
Let us say script2.ksh got failed due to some reason and when I rerun the Main.ksh script It should start from script2.ksh onwards.
Actually, I have so many commands and scripts in Main.ksh.I want this restartbility for entire script and How to do this?
if sh -x script1.sh > script1.log
then job=$((job + 1))
date "+$job %c" > status
else echo "Failed due to some reason"
exit 1
fi
When job=$((job + 1)) and date "+$job %c" > status will be executed?
Case1:-Let us assume sh -x script1.sh is success and it will return 0 and it will execute else part
echo "Failed due to some reason"
Case2:-Let us assume sh -x script1.sh is failed and it will return non-zero and it will execute then part
job=$((job + 1)) and date "+$job %c" > status
It will increment the job value and also update the status.
if (the keyword) is basically: goto then if the following command returns zero, otherwise go to the else -part. That means:
if sh -x script1.sh > script1.log
means "if the return code of sh -x script1.sh is zero". Both your scenarios cannot happen therefore, it is the other way round: if the job returns 0 then the variable $job is incremented (and the log entry is written and if it fails the script exits with 1.