Shell script to schedule jobs

Dear all,
I have to create a shell script which will run the job during weekday/weekend in following manner: -
There are 3 jobs

JB_1 
JB_2
JB_3

These jobs changes its flag to "COMPLETED" in below 2 ways

  1. These 3 jobs which runs after the completion of previous one i.e JB_1 runs and changes its flag to "COMPLETED" then only the next job gets started.
  2. The second way to change the jobs status to "COMPLETED" without running it with the following command: -
CHANGE_FLAG JB_1=COMPLETED ---- if i run this command at the prompt followed job name= completed, it changes its flag.Same goes for JB_2 and JB_3

Now my concern is how should i create a shell script to do the above activities during weekday and weekend as mentioned below.

During weekday (Monday to friday) these jobs should simply change its flag to COMPLETED as mentioned in point 2.
During weekend (Saturday and Sunday) these job should run and then changes its flag to COMPLETED as mentioned in Point 1.
What these jobs internally does is irrelevant.

whats wrong with using cron? why are you re-inventing the wheel?

Crontab doesnt work here...need to write a shell script for that..

Please post detailed explanation when you say something doesnt work. When you say crontab, are you saying there are problems with editing the cron entry or the cron daemon is not working or running?

We use autosys and not crontab...

There are other schedulers that are more sophisticated than cron. In this case it sounds like the scheduler of choice provides conditional execution where Job-b depends on the successful execution of Job-a and thus Job-b isn't run until Job-a finishes and was successful. Cron makes no provision for conditional execution and thus isn't useful.

Something like this might be what you need. During the week, it executes the change flag script/programme and exits (good). On Saturday and Sunday it executes what ever you need.

#!/usr/bin/env ksh

case $(date +%a) in
    Sun|Sat)    ;;     # do nothing here, do real work after the case

    *)      CHANGE_FLAG JB_1=COMPLETED;   # nothing to be done, just change and exit 
            exit 0
            ;;
esac

echo "doing the real work now"
CHANGE_FLAG JB_1=COMPLETED
exit 0

Should work in bash too.

1 Like