Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell Script to run weekly jobs

Status
Not open for further replies.

mpramods

Technical User
Jun 3, 2003
50
0
0
US

I need to write a script to run weekly jobs on particular days of the week.

e.g., The schedule of Jobs could be as follows:
1. Job A needs to run every Monday at 10:00 AM
2. Job B needs to run every Monday at 3:00 PM
3. Job C needs to run every Tuesday at 12:00 PM
4. Job D needs to run every Thursday at 10:00 AM

and so on for few more jobs.

I cannot schedule this using Control M or Cron Tab. Is there any way I can achieve this by writing a shell script?

 
You could use something I this code that runs every two weeks. It actually runs weekly via an application, but it only runs if the Semaphore exits. If not, it does it run...or something like that. Anywho, here's the code:

Code:
CHMOD=/usr/bin/chmod
SEM=/tmp/flag
WDIR=/tmp/working_dir
if [[ -e ${SEM} ]]
then
   rm ${SEM}
   if [[ -s ${WDIR}/xxx.csv &&  -s ${WDIR}/xxxtime.csv ]]; then
      mailx -s "The file uploaded. Please run XXXX." hr_users < /dev/null
   else
      mailx -s  "Error...file has not been received. Please contact IS dept" hr_users < /dev/
null
   fi
else
#  SET THE FLAG FOR PAYROLL WEEK
#
   /usr/bin/touch ${SEM}; ${CHMOD} 700 ${SEM}
fi
exit

Hope this makes sense to you. Thanks.
 
I just re-read your post. I thought you were trying to run your jobs every other week. My mistake.
 
1. Job A needs to run every Monday at 10:00 AM
2. Job B needs to run every Monday at 3:00 PM
3. Job C needs to run every Tuesday at 12:00 PM
4. Job D needs to run every Thursday at 10:00 AM

Not in crontab?

Guess again:

[tt]
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

0 10 * * 1 /path/to/jobA >/tmp/jobA.out 2>/tmp/jobA.err
0 15 * * 1 /path/to/jobB >/tmp/jobB.out 2>/tmp/jobB.err
0 12 * * 2 /path/to/jobC >/tmp/jobC.out 2>/tmp/jobC.err
0 10 * * 4 /path/to/jobD >/tmp/jobD.out 2>/tmp/jobD.err
[/tt]


HTH,

p5wizard
 
p5wizard,
The solution you mentioned uses Cron Tab. I cannot use Cron Tab to do this.
Is there any way, I can do this using a Unix Shell script?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top