Script should check and run only on Sunday


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script should check and run only on Sunday
# 1  
Old 06-20-2014
Script should check and run only on Sunday

Hi All,

I have a script, I want to make sure the script should check whether the day is sunday, only then it should run, if it is run other days it should check and exit the script.


Kindly help.

Thanks in Advance !!
# 2  
Old 06-20-2014
Try - if available on your system which you do not mention - to test
Code:
date +%w

being 7.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 06-20-2014
Sorry,

My Server is Solaris 10
# 4  
Old 06-20-2014
If you are using cron, you can schedule scripts to run only certain
days of the week.Here is a wiki page for cron.

Cron - Wikipedia, the free encyclopedia

Here is a sample job that will run at 6AM every Sunday morning.
Having the redirect at the end will prevent you from getting emails
if the script produces output.

Code:
0 6 * * 0  /home/username/test.pl > /dev/null 2>&1

This User Gave Thanks to gandolf989 For This Post:
# 5  
Old 06-20-2014
Hi,

thanks for replying...

I am using autosys for scheduling, and any one can request for start of this job,

But my requirement is, when some one runs this script, script should run and check that it if current day is sunday only then it should run.

In the above command which Rudi gave
Code:
date +%w

I will need to see if I can check the below way
Code:
 day=`date +%w`
 a=7
 if [ $day = $a ]
 then 
 #### Script will continue to run ####
 else
 echo" THis script will run only on SUnday"  
 exit 1
 fi

# 6  
Old 06-20-2014
Or more simply (assuming the capital H and U were typos, and fixing the quoting error):
Code:
if [ `date +%w` -ne 0 ]
then
        echo "This script will run only on Sunday"  
        exit 1
fi
# perform desired actions...

Note that according to the standards, date +%w should return 0 on Sunday; not 7. Check the man page for date on your system to determine whether you should use:
Code:
if [ `date +%w` -ne 0 ]

or:
Code:
if [ `date +%w` -ne 7 ]


Last edited by Don Cragun; 06-20-2014 at 04:18 PM.. Reason: Sunday 0 or 7?
These 2 Users Gave Thanks to Don Cragun For This Post:
# 7  
Old 06-20-2014
My fault - %u is 1 - 7, thus Sunday will by 7 then. With %w, 0 is Sunday.
This User Gave Thanks to RudiC For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run script on every last sunday of the month

Hi ALL, I have been testing this script to run for every last Sunday of the month,looks like month which have 5 sunday (july 2016 )is not passing this and failing every time. Here is what I am using, current_date=31 echo " CURRENT DAY -> $current_date" if ... (2 Replies)
Discussion started by: netdbaind
2 Replies

2. Shell Programming and Scripting

How to check if script is run via cron or manual=command line?

Hi all, I have a script that can be run via cron or via the command line. Is there any way that I can place something on the script to be able to distinguish/differentiate whether the script was run via a user in the command line or whether it was run from the cron? (3 Replies)
Discussion started by: newbie_01
3 Replies

3. Shell Programming and Scripting

Script to run php and check value in txt

Hello, I'm looking for a bash script, that I will run from cron, that executes a php script. After 5 minutes that the php script is executed, the bash script, must check a value in a text file /public_html/check.txt if check.txt = 0 the script will stop, if check.txt is not = 0 it must... (0 Replies)
Discussion started by: andymc1
0 Replies

4. UNIX for Advanced & Expert Users

Autosys job run on Sunday

Hi, I need to create a autosys job which will run on every sunday at 7:30 AM NY time for each 10 min interval of time. days_of_week: su start_mins: 0,10,20,30,40,50 run_window:"07:30" Is it fine? Please help Thanks, Anup (2 Replies)
Discussion started by: anupdas
2 Replies

5. UNIX for Dummies Questions & Answers

Run script on every second sunday

I was to schedule a script in a crontab after every 15 days specically on every 2nd Sunday. I know that i can schedule on basis of weekdays, but can it be done by skipping in between???:wall: (5 Replies)
Discussion started by: masquerer
5 Replies

6. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

7. Shell Programming and Scripting

Crontab job to run every sunday

Hello, I wanted to run one of my shell script for every sunday at 5PM. Here is the crontab entry i am using.. 00 17 * * 0 /inventory/update.sh > /inventory/update.log 2>&1 The job is not kicking on sunday at the specified time.. Am i missing anthing? Any help is appreciated... (2 Replies)
Discussion started by: govindts
2 Replies

8. Shell Programming and Scripting

Check if script run by a user directly or via other scripts

Hi, i have a script 'a.sh' that should be called only by certain scripts like b.sh, c.sh Inside a.sh, how can i determine 1) if this script was run directly from command prompt (or scheduler) 2) if called via other scripts? Is there an easy way to get parent process name (not just pid),... (2 Replies)
Discussion started by: ysrinu
2 Replies

9. Solaris

How to check for Saturday or Sunday

Hi , I have a date parameter passed in YYYYMMDD format , how can I check whether it is Sat or Sun on Solaris box , as we can do the same easily on linux box by using date -d YYYYMMDD '+a' . Any pointres will be really helpful . (5 Replies)
Discussion started by: harpreetanand
5 Replies

10. Shell Programming and Scripting

check in unix shell script so that no one is able to run the script manually

I want to create an automated script which is called by another maually executed script. The condition is that the no one should be able to manually execute the automated script. The automated script can be on the same machine or it can be on a remote machine. Can any one suggest a check in the... (1 Reply)
Discussion started by: adi_bang76
1 Replies
Login or Register to Ask a Question