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
# 29  
Old 06-24-2014
Apologies for the confusion...
My requirements are still the same.
1. Script should run only on sunday.
2. If my internal code runs to success in 3 attempts. Counter should reset to 1 and exit.
3. If the interal code failed on the 3rd attempt. It should send an email and exit. Here again the counter should be reset to 1.

---------- Post updated at 09:14 AM ---------- Previous update was at 09:11 AM ----------

Will post the code in some time as I am away from my laptop. .
# 30  
Old 06-24-2014
With the modified code I gave those requirements are met.

You have a bonus too...

The value n=3 was deliberately chosen to execute the final "if" statement AND also give you an email to flag if someone was trying to run it on any other day than Sunday as well as resetting the value back to n=1 ...

Of course you can still exit 1 there if you so desire and not have these extra emails that is why it is just commented out...
This User Gave Thanks to wisecracker For This Post:
# 31  
Old 06-25-2014
yes wise cracker, I will check with yours and bakunins code on different servers this sunday.. and get back with my findings...

Thanks again!!

Last edited by nanz143; 06-25-2014 at 12:42 AM..
# 32  
Old 07-01-2014
Hi bakunin,

I had an error msg.

error msg:
Code:
grep: RE error 41: No remembered search string.

My mistake i have not mentioned absolute path of attempts.log

Please help me understand how the values of fLog are.

As per my understanding, fLog and attempts.log should be given with absolute path.
I have deployed my scripts in the below path

Code:
path: /usr/local/wam/scripts

Kindly suggest, Below is the code

Code:
PCheckDOW ()
{
typeset chDOW="${1:0:3}"
if [ "${chDOW}" != "Sun" ] ; then
     return 1
fi
return 0
}
pCheckAttempts ()

{
typeset fLog="${1}"
typeset iCurrDay="${2}"
typeset iNrOfAttempts=0
typeset iMaxAttempts=3
grep "$iCurrDay" "$fLog" > "${fLog}.tmp" 
mv "${fLog}.tmp" "${fLog}"
echo "$iCurrDay" >> "$fLog"
iNrOfAttempts=$(grep -c "$iCurrDay" "$fLog")
if [ "$iNrOfAttempts" -gt "$iMaxAttempts" ]
then
     echo "Attempts $iNrOfAttempts exceeded maximum of attempts $iMaxAttempts, Sending mail"

return 1
fi
return 0
}

# 33  
Old 07-10-2014
Quote:
Originally Posted by nanz143
Code:
grep: RE error 41: No remembered search string.

I have no idea where that comes from.

Quote:
Originally Posted by nanz143
Please help me understand how the values of fLog are.

As per my understanding, fLog and attempts.log should be given with absolute path.
I have deployed my scripts in the below path
It does not matter where your script is. Change the one line:

Code:
typeset fAttemptsLog="/tmp/attempts.log"

To put the attempts.log file somewhere else and/or name it differently. "fLog" will hold what is given to the function as the first argument. As long as it points to a valid file everything is fine.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 34  
Old 07-14-2014
Thanks bakunin, Sorry for my delayed response as i need to test it only on sundays.
So as i need attempts.log in
Code:
/usr/local/wam/scripts

I am modifying as below, suggest me if i am wrong.

Code:
typeset fAttemptsLog="/usr/local/wam/scripts/attempts.log"

------------


I Also realized a mistake that i did with out path....

Code:
typeset fAttemptsLog="attempts.log"

.

Last edited by nanz143; 07-14-2014 at 12:55 PM..
# 35  
Old 07-15-2014
Quote:
Originally Posted by nanz143
So as i need attempts.log in
Code:
/usr/local/wam/scripts

I am modifying as below, suggest me if i am wrong.

Code:
typeset fAttemptsLog="/usr/local/wam/scripts/attempts.log"

Exactly. In general, whenever you mention a file in a script you should ALWAYS do it with a full path. This way the script will work regardless of where it is run from.

Quote:
Originally Posted by nanz143
Code:
typeset fAttemptsLog="attempts.log"

.
This is exactly what you should avoid. This will place the log file whereever the script happens to be called at (this palce could differ from one run to the next) and is a first-rate device to clutter up your filesystems with an abundance of abandoned "attempts.log"-files.

I hope this helps.

bakunin
This User Gave Thanks to bakunin 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