Code to make sure Script runs only on sunday -


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Code to make sure Script runs only on sunday -
# 1  
Old 05-02-2013
Code to make sure Script runs only on sunday -

Hi

I have written a script which restarts the application , I want to add a piece of code in my script , to make sure this gets executed only on sunday .
So that even if someone runs it on any other day by mistake it should exit throwing an error message . Can someone please assist what will be the code for this .

I wrote something like this -

Code:
week=`date|awk '{print $1}'`

if [ $week == "Sun" ]

then 

script code 

else 

exit

fi

Is it fine ? Please give suggestions if there is any other better way to this ?

Last edited by jim mcnamara; 05-02-2013 at 09:28 PM..
# 2  
Old 05-02-2013
I think it's fine. Smilie I changed it a little.
Code:
day=`date | awk '{print $1}'`

if [ $day = "Sun" ]
then
  script code
else
  exit
fi

# 3  
Old 05-02-2013
Why to use awk if date command itself has an option to print abbreviated weekday name!
Code:
date +"%a"

# 4  
Old 05-03-2013
Why not put the script details in CRON and schedule it to run only on SUNDAYS every week.It doesn't need manual efforts to run the script
# 5  
Old 05-03-2013
Code:
[ $(date +"%w") -eq 0 ] && script code || exit

# 6  
Old 05-03-2013
This is a very typical job for cron
Code:
crontab -e

add
Code:
00 00 * * 0 /div/yourscript

runs 0:00 every sunday
# 7  
Old 07-15-2013
while working in crontab, one must be careful about fields & respective timings
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. High Performance Computing

Python code runs on login node but not on cluster

I work for one of my professors and we are trying to run SU2 in parallel on a cluster owned by the university that uses slurm for its workload manager. The problem we are running into is that when we ssh into the cluster and run the command: parallel_computation.py -f SU2.cfg on an assigned... (0 Replies)
Discussion started by: devinmgibson
0 Replies

2. 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

3. Shell Programming and Scripting

Trigger the script if it is first sunday of the quarterly month

Hello All, I have script which needs to be scheduled in crontab which needs to be run only on the first sunday of the quarterly months (March, June, September,Dec). Can anyone please help me out on this. Thanks, Arun. (13 Replies)
Discussion started by: Arun1992
13 Replies

4. UNIX for Dummies Questions & Answers

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 !! (41 Replies)
Discussion started by: nanz143
41 Replies

5. UNIX for Dummies Questions & Answers

Script only runs as a particular user

Hi guys So I've got this PERL script that for one reason or another I need to run as a user other than the user that created the script. When I su - to another user the script won't run and doesn't give me any output as to why. No permission denied or anything like that. I've chmod 777'd the... (5 Replies)
Discussion started by: Jaymoney
5 Replies

6. 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

7. Shell Programming and Scripting

Shell script which runs sql script

Hi all, I need a shell script which runs a sql script but I couldn't find how to finish it. This is the code that I have: #! /usr/bin/ksh export SHELL=/bin/ksh export ORACLE_SID=database export ORACLE_HOME=/opt/oracle/product/9.2.0.8 sqlplus user <<EOF @/path/path/path/scriptname.sql... (3 Replies)
Discussion started by: Geller
3 Replies

8. Shell Programming and Scripting

Shell Script: want to insert values in database when update script runs

Hi , I am new to linux and also also to shell scripting. I have one shell script which unpacks .tgz file and install software on machine. When this script runs I want to insert id,filename,description(which will be in readme file),log(which will be in log file) and name of unpacked folder... (1 Reply)
Discussion started by: ring
1 Replies

9. UNIX for Advanced & Expert Users

My script runs too slow :-(...

Hello experts, I have a series issue in script that result with bad peformence and I wonder if you can assist me. For example I have two files: File-New, size 15Mb. File-Old, size 1Mb. File-New content: a b c k File-Old content: d f a b (0 Replies)
Discussion started by: roybe
0 Replies
Login or Register to Ask a Question