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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix Cron 1

Status
Not open for further replies.

souper

Technical User
May 11, 2001
2
US
Hello All,
I do not use UNIX but I need help with a UNIX scenario.

I am interested in having a cron job run every Friday or the 1st of each month. (The cron will extract data into a CSV file.)
1) If the 1st is a Friday, will the cron automatically ensure that it only runs once?
2) Also if the 1st is a Saturday I don’t want the file to be generated (long story). I understand that the cron itself would run when scheduled and execute the script it’s told to. Is it possible to have a conditional check in the script to see if the 1st is a Saturday and if it is quit the job?

If you could let me know if these two points are possible and point me in the direction to research them (ie what command for the conditional logic and what command for determining the Day of Week) I would appreciate it.
Thanks
 
Hi
My suggestion is you should write your own script first and then people will help you out (For me, it's hard to write a complicate script, but I try my best !!!) and do 1 step at a time.

Keep your cron file simple as you can because I view the cron file as a schedule job, not an application or a complicate script to do work (means don't put condition in this file, as the matter of fact, you can specify what date and time to run it).

So you can create 2 files:
- one script (named it scriptA) will do the true work
- the second one (named it scriptB) will call the scriptA, now in scriptB, you can put the condition in to say, eg:

If it is the 1st day of the month,then don't call scriptA, etc, then you don't have to worry the cronjob run everyday, your scriptA will not work due to the condition in scriptB

Hope give you some ideas
 
Hi Souper

-------------------------------------------------------
# This script will execute on 1 st of every month as cron
#!/bin/ksh
# This is Script2
DATE_DAY=`date +"%a"`
if [ $DATE_DAT = Fri ]
then
exit 0
else
Call Script1
fi
-----------------------------------------------------

# This script executes every Friday as cron job.
# This is script1
#!/bin/ksh
Your actual job as a script goes here

Hope this helps

--Sethu
 
Thanks for the help. This puts me in a solid direction. I have voted for each of you that the post was helpful.
Souper
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top