Schedule and Run By weekly shell script in cronjob | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Schedule and Run By weekly shell script in cronjob

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-07-2013
krupasindhu18 krupasindhu18 is offline
Registered User
 
Join Date: Sep 2011
Last Activity: 23 July 2014, 3:59 AM EDT
Location: Chennai,India
Posts: 76
Thanks: 13
Thanked 1 Time in 1 Post
Schedule and Run By weekly shell script in cronjob

Hi All,

How to schedule a shell script(script name- byweeklyreport.sh) it should run by weekly in corn job or is there any script have to write to check week and then run the above script.
example-1st run March 06 2013
2nd run March 20 2013
3rd run April 3 2013 like that
please give some example except PERL Script


Thanks all in advance

Regards,
Krupa
Sponsored Links
    #2  
Old 03-07-2013
RudiC RudiC is online now Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 27 August 2014, 4:50 AM EDT
Location: Aachen, Germany
Posts: 4,116
Thanks: 67
Thanked 979 Times in 928 Posts
Man Page for crontab (linux Section 5) - The UNIX and Linux Forums
Sponsored Links
    #3  
Old 03-07-2013
krupasindhu18 krupasindhu18 is offline
Registered User
 
Join Date: Sep 2011
Last Activity: 23 July 2014, 3:59 AM EDT
Location: Chennai,India
Posts: 76
Thanks: 13
Thanked 1 Time in 1 Post
Hi,
Sorry actually i need example for this,that you have provided information is not enough.

Thanks
Krupa
    #4  
Old 03-07-2013
Jotne's Avatar
Jotne Jotne is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 22 August 2014, 7:56 AM EDT
Posts: 1,040
Thanks: 62
Thanked 216 Times in 204 Posts
Every week

Code:
0 0 * * 0 byweeklyreport.sh

CronBuddy - a crontab sandbox

Last edited by Jotne; 03-07-2013 at 07:56 AM..
Sponsored Links
    #5  
Old 03-07-2013
rbatte1 rbatte1 is online now Forum Staff  
Moderator
 
Join Date: Jun 2007
Last Activity: 27 August 2014, 4:45 AM EDT
Location: Lancashire, UK
Posts: 1,745
Thanks: 557
Thanked 296 Times in 265 Posts
Depending on the OS you are using, you may have a cron setup that works for every two weeks, but by using the date command in your script you could schedule it weekly and they choose whether to actually execute or not.

On many flavours of unix, you may find that
Code:
date +%j

gives the Julian date. Given that there are seven days in a week, you could schedule every Monday and then have a test for "Is today an even Julian date?" test at the top.

Some other flavours will give the week of the year, and it's a similar thing, but probably using Julian date is the best.

So an entry for cron:-

Code:
$ crontab -e
0 4 * * 1 /home/myuser/myscript

will run this every Monday at 4am. You could then code your script like this:-

Code:
#!/bin/ksh

juldate=`date +%j`
((jultest=$juldate/2))
((jultest=$juldate*2))

if [ $juldate -ne $jultest ]
then
   print "This is an odd week of the year."
   print "No actions performed."
   exit
fi

# I have confirmed it is an even numbered Monday, so proceed

blah blah blah.......

Of course, you could make the test -eq to say you want to ignore even numbered Mondays. The divide by two, multiply by two relys on odd numbers division getting the 0.5 truncated, so if the Julian date is 123, the half is only counted as 61, so double it again and you get 122. Test then finds that they are different.


Does this help?



Robin
Liverpool/Blackburn
UK
Sponsored Links
    #6  
Old 03-07-2013
RudiC RudiC is online now Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 27 August 2014, 4:50 AM EDT
Location: Aachen, Germany
Posts: 4,116
Thanks: 67
Thanked 979 Times in 928 Posts
Quote:
Originally Posted by krupasindhu18 View Post
Hi,
Sorry actually i need example for this,that you have provided information is not enough.

Thanks
Krupa
Had you taken the time to read that man page, you would have found an example exactly dealing with and solving your problem.
Sponsored Links
    #7  
Old 03-26-2013
krupasindhu18 krupasindhu18 is offline
Registered User
 
Join Date: Sep 2011
Last Activity: 23 July 2014, 3:59 AM EDT
Location: Chennai,India
Posts: 76
Thanks: 13
Thanked 1 Time in 1 Post
Hi,
Actually my Requirement is like this :-
I have shell script in kern shell ,have to run alternate week per month
example-today's date is 27 Mar 2013 and my script will run today then for the next time when it will run it should check 1st what was the last run date(27 Mar 2013) if it is matched 15days from current date then run else sent a mail with waning mgs.

i have a AWK command it is checking only within a month
Code:

Code:
date +%Y:%m:%d|awk -vFS=":" -vOFS=":" '{$3=$3-3;print}'

suppose i am checking 20days from current date it is give some negative value(-8)
ex-2013:03:-8

I hope you will understand my problem.
Advance thanks for giving me solution.

Thank you All.

Regards,
Krupa

---------- Post updated at 04:08 AM ---------- Previous update was at 04:05 AM ----------

Quote:
Originally Posted by Jotne View Post
Every week

Code:
0 0 * * 0 byweeklyreport.sh

CronBuddy - a crontab sandbox

i don't think you are reading properly my thread
please read carefully and replu me back

Last edited by Franklin52; 03-26-2013 at 05:39 AM.. Reason: Code tags
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Best way to schedule script to run Ubuntu 10.04 glev2005 UNIX for Dummies Questions & Answers 1 02-04-2011 12:42 PM
Schedule a script to run at 10am from mon to fri firestar Shell Programming and Scripting 7 01-21-2011 12:24 PM
My script didn't run every run every minute at cronjob ngaisteve1 AIX 4 08-13-2010 01:03 AM
How to schedule a cronjob to run every 15 mins ? suresh_kb211 Shell Programming and Scripting 5 08-26-2009 04:57 AM
General Q: how to run/schedule a php script from cron jobs maybe via bash from shell? lowmaster Shell Programming and Scripting 3 05-18-2009 09:32 AM



All times are GMT -4. The time now is 04:50 AM.