473,543 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do i get my cron to run only on weekends

11 New Member
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 32151
anirudhbapu
11 New Member
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
anirudhbapu
11 New Member
Can anybody help me............. ............... .
Jan 20 '09 #3
numberwhun
3,509 Recognized Expert Moderator Specialist
@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
anirudhbapu
11 New Member
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 Recognized Expert Moderator Specialist
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
anirudhbapu
11 New Member
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..TH IS 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 Recognized Expert Top Contributor
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
anirudhbapu
11 New Member
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
2662
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
3037
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 dns records at my dns provider, zoneedit. So basically, I've setup dynamic dns using python. Once the ip compare and/or update is complete, I log...
3
10294
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 following: runs several queries against different tables in a database; returns several lists of pictures being used in the database; removes any...
5
3541
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 = localtime(time); print DATA "@Now\n"; exit ;
4
3930
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 4.4 32bit. Php does run as an Apache SO. It works perfectly if I just hit the page in a web-browser (output to browser). It works *perfectly*...
5
2313
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 logged in to a particular website at the current moment. Would it cause me trouble if I made this array static? If it would cause trouble, what's the...
4
7494
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 variable is not in the os.environ dictionary. I know that cron runs in a subshell that does not have all of the normally set environment variables. ...
0
3448
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 do not inherit this value. From "man bash": Shell Variables The following variables are set by the shell:
1
2292
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 and for each event do the work needed. It's basically like unix cron or like a calendar application with some restrictions. The outer loop may...
0
7735
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7688
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5885
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4895
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
968
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
636
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.