Shell script to run multiple jobs and it's dependent jobs

I have multiple jobs and each job dependent on other job.
Each Job generates a log and If job completed successfully log file end's with JOB ENDED SUCCESSFULLY message and if it failed then it will end with JOB ENDED with FAILURE.

I need an help how to start.

Attaching the JOB dependency .... Please help me here how to start.

My old eyes are having difficulty deciphering the names of your jobs. And, with lines running through or behind some jobs, not all of the dependencies are clear.

Do you really have to read the log files to determine whether a job completed successfully? Why aren't your jobs written to exit with a zero exit status on successful completion and a non-zero exit status on failure? If you do have to decipher log files, what are the names of the log files?

What arguments need to be passed to your jobs? What I/O redirections need to be set up for your jobs?

1 Like

Thank you for your reply.

My log name starts with name of the job ... If suppose Job name is X then log name will starts with X.
No arguments needed.. just we need to run in below format.
RunJobs X BYREQ ( Format to run the job).
We can run the job from any path and it creates the log at Home directory.

I repeat: Do you really have to read the log files to determine whether a job completed successfully? Why aren't your jobs written to exit with a zero exit status on successful completion and a non-zero exit status on failure? If you do have to decipher log files, what are the names of the log files?

And, what operating system and shell are you using?

With a shell based on Bourne shell syntax, you can run a job and the shell variable $? will be set to the exit status of the last command completed.

When you get to a point where you want to run more than one job in parallel, you can start a job in the background using something like:

RunJobs X BYREQ &

(with the & telling the shell to run the command preceding the ampersand in the background) and immediately after that you can use something like:

Xpid=$!

which will then save the process ID of the job you just started in the background. Then when you have started all of the processes in the background that can run independently, you can wait for the completion of that job with:

wait $Xpid

and the exit status of the wait command will be the exit status of that job.

You can then paste these pieces together with shell commands to determine whether to start other jobs (if the dependencies completed successfully) or quit (if one of the dependencies failed).

If you can't use the exit status of a job to determine if it succeeded, you can use something like:

if grep -q SUCCESSFULLY JobXlogfile
then	DoWhateverYouNeedToDoOnSuccessfulCompletion
else	DoWhateverYouNeedToDoOnFailure
fi

In all cases in the above examples, everything in italics needs to be replaced by code you supply and all cases of X need to be replaced by your job names.

This should be enough to give you an idea of where to start. But, a project like this is fairly complex if this is your first attempt at writing a shell script.