473,322 Members | 1,473 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,322 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 32131
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.