473,395 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how do i get my cron to run only on weekends

Hello people,
I have a daily script which i execute it manually on daily basis..
1.On week days i need to run this script on 8 in the morning
2.ON week ends i need to run this at 8 in the night (only saturday and sundays).
3.Also In above two scenarios the 1st of every month should not be included and some special scipt runs on 1st of every month..

I could manage to find the solution for the 8 in the morning issue..
But failed for the week ends..

Below is the entries in the cron, the first one works fine but the second one(WEEKENDS) executes on week days as well as week ends....

##WEEKDAYS
00 08 2-31 * 1-5 /usr/.............

##WEEKENDS ()
00 20 2-31 * 0,6 /usr/........

PLease help, i just need to run only on saturday and sundays at 8 in the night except the 1st of every month........
Jan 19 '09 #1
8 32139
Look there is a catch in the WEEKENDS cron entry..
I dont want to run this entry on 1st of month, but rather it shud run only on saturday and sunday accept 1st of every month...
Jan 19 '09 #2
Can anybody help me.............................
Jan 20 '09 #3
numberwhun
3,509 Expert Mod 2GB
@anirudhbapu
Sorry for the delay in trying to help you.

Cron itself is a funny beast. You will find that shortcuts or methods that work on one machine's cron may or may not work on anothers. This is typically due to different versions of cron.

To see the manual page that explains the sections of the crontab, use this:

Expand|Select|Wrap|Line Numbers
  1. man -s 5 crontab
  2.  
As for your issue on the weekends, have you tried specifying the days using the day names? Here is an example:

Expand|Select|Wrap|Line Numbers
  1. ##WEEKENDS ()
  2. 00 20 2-31 * Sat,Sun /usr/........
  3.  
If that does not work, then try something like "6,7", where 6 is Saturday and 7 is Sunday, instead of 0,6 as you have it.

Again, you just have to play with crontab to get everything right and working properly.

Regards,

Jeff
Jan 21 '09 #4
Thanks Jeff for the reply....
i have checked and read the manual for the crontab very carefully..but it doesnt mention properly about the weekend stuff which i require....
They have just explain the overview for the same...
Also i tried with 0,6--what it does with is ....it execute the cron at 0 (Sunday) and 6 (Saturday) and also it executes on 2-31 which i dont want....

According to your suggestion if i put 6,7..the entry will look like below...
00 20 2-31 * 6,7 /usr/.../.../.../ > /dev/null 2>&1....

the above cron entry again says that the command will execute on 6 and 7 (i.e saturday and sunday) and also it will run on 2-31..

I hope u got me, what iam trying to say......

What i exactly want is---i have only one script, i need to execute that script on week days at 8 in the morning and on week end it will execute at 8 in the night..Also the cron entry should take care that it should not run on 1st of every month.....
Jan 21 '09 #5
numberwhun
3,509 Expert Mod 2GB
I think you are contradicting yourself. You said in your original post you want this to run all days but the 1st and in this one, you said: "and also it executes on 2-31 which i dont want". Not to question you, but do you or don't you want it running on every day but the 1st? If you only want it run on the 1st, just put a 1 in place of the 2-31.

Regards,

Jeff
Jan 21 '09 #6
Sorry..i guess u took me wrong..let me explain once again...

I have placed 2 lines in cron..
one for week days to be executed at 8 in the morning
And other at week ends to be executed at 8 in the night..

BUT BOTH THE SCRIPT ARE SAME BUT WITH DIFFERENT TIMINGS...

1.
##WEEKDAYS
00 08 2-31 * 1-5 /usr/.............

2.
##WEEKENDS ()
00 20 2-31 * 0,6 /usr/........

Now as per the first entry it will run on all weekdays (From mon to friday (1-5) and 2-31 ie; on all days except sat/sun and 1st of every month)..

Now if u see the second entry its mentioned 0,6 that is sat and sunday also it is mention 2-31...this mean over here it is running on sat and sun as well as 2-31 ie;everyday..THIS IS THE THING I DONT WANT.I WANT THE SECOND ENTRY TO BE RUN ONLY ON SAT AND SUN BUT NOT ON 1st.
So the same script is executing at sat and sun as well as all the weekday which is already executing in 1 entry at 8 in the morning...

How should i make the 2nd entry possible to be executed by cron only on weekends and no other day and not on 1st of every month ofcourse.....

I HOPE U UNDERSTOOD MY PROBLEM.....
Jan 22 '09 #7
gpraghuram
1,275 Expert 1GB
For the second cron...start the script on all saturday and sunday and inside the script use the date command to determine the date and then if its 1st of the month then exit.


Raghu
Jan 23 '09 #8
Can you pls tell me the exact entry for sat and sun only..and also the date script to be put into my script..

will that be like below.....
if [ `date "+%d"` -eq 1 ]
then
echo " Script wont be executed...... "
exit 1
else
Jan 23 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: sherryonline | last post by:
i have a page and i need that page to be called every day at 12:00 that page is going to connect to the database fetch some emails and will start mailing them how i am goning to do this.
4
by: vagrantbrad | last post by:
I'm using python 2.4 running on Fedora Core 4. I have written a python program called ipscan.py that checks the external ip address of my cable internet connection, and on change, will update the...
3
by: the.natalie | last post by:
Hi. I am a newbie to mysql, cron, and shell scripting, so please bear with me. I have a script that is used for updating an image directory based on contents in a database. The script does the...
5
by: jcor | last post by:
Hi, I'm trying to run my first cron job, probably it's missing something. I created a perl script just to test, it's called "teste" !/usr/bin/perl open(DATA,">>/home/joao/files/output"); @Now...
4
by: Phil | last post by:
I have a php script that queries some Oracle DB and outputs a single line of plain text with <brat the end for each query. This is Apache2, php4.4.8 and Oracle Instant Client 10.1.0.5 all on CentOS...
5
by: Lawrence Krubner | last post by:
Do any problems come up when using a static variable in a cron job? Assuming the cron job is called every 5 minutes for one year. Assume I've got an array that stores the names of which users are...
4
by: Stephen Cattaneo | last post by:
Hello all, I am attempting to execute an automated test (written in Python) via cron. I have to check the HOSTNAME variable as part of the test, oddly under cron the HOSTNAME environment...
0
by: Cameron Simpson | last post by:
On 17Aug2008 21:25, John Nagle <nagle@animats.comwrote: Because $HOSTNAME is a bash specific variable, set by bash but NOT EXPORTED! Like $0 and a bunch of other "private" variables, subprocesses...
1
by: Karthik Gurusamy | last post by:
Hi, I'm working on a cron like functionality for my application. The outer loops runs continuously waking every x seconds (say x=180, 300, ..). It needs to know what events in cron has expired...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.