Write a script to send alert for some particular hours in a day


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Write a script to send alert for some particular hours in a day
# 1  
Old 03-26-2009
Question Write a script to send alert for some particular hours in a day

Hi All,
I have a have a script which checks for some processes whether they are running or not and if they are not running then it send a mail specifying that the processes are not running.
This particular script example abc.ksh is runs in a cron like this
Code:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /home/usha/abc.ksh

Now my problem is everyday for total four hours say morning 6 to 8 and evening 6 to 8 these processes will not run and there is a scheduled downtime.And i have been told that cron entry should not be changed.
So, is there any way to add any condition in my script itself to the part where i am sending a mail to check for the time and if it is between morning 6 to 8 and evening 6 to 8 then it will not send a mail.Else if it is any other time of the day then it will send a mail..
Thanks to all in advance.

Last edited by Yogesh Sawant; 03-29-2009 at 02:22 PM.. Reason: added code tags
# 2  
Old 03-26-2009
Hi,

Just include condition inside your script..before checking the process status..

check current timestamp which should not be 6-8 AM
if that condition is true..
then check for current timestamp which also should not be 6-8 PM
if both the condition is true then go ahead and check for process..
if anyone of the condition is true then give exit..withou checking process..

Thanks
SHa
# 3  
Old 03-27-2009
Could you please let me know how can i implement this???

Thanks
Usha
# 4  
Old 03-27-2009
its better to share yur codes...rather than giving different solutions..

Code:
if [ condition ]
true
exit 1;
if [ condition ]
true
exit 1;
  fi
    fi

Thanks
Sha
# 5  
Old 03-27-2009
Thanks, for your reply.But i am aware of if condition syntax but my problem how to test that the time is between morning 6to 8 and evening 6 to 8 and the not to send mail alert during that time.I have a problem incorporating this in my script.
do i need to assign some variable with the date command but then how to check cor two hours as my script has to run 24 hours.but inside my script the mail alert will not be sent for some amount of time.but it sends alerts for the rest of the time.

Thanks
# 6  
Old 03-27-2009
Code:
#!/bin/ksh
echo "Print Current Time"
v=`date +%H`
echo $v
                if [[ $v -ge 6 ]] && [[ $v -le 8 ]]; then
                        echo "please get exit"
                        exit 1;
                                else
                if [[ $v -ge 18 ]] && [[ $v -le 20 ]];then
                        echo "Please get exit"
                        exit 1;
                                else
                        echo "check for process"
                        echo "mail part"
                  fi
                fi

Thanks
SHa
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to send mail alert

Hi I have below shell script to send mail alert , however I want to add more functionality in this script and that is , script should only check that file between 9 am to 5pm , and if there is no activity in this time 9 am to 5 pm for 2hours then it should give me mail alert, please help... (2 Replies)
Discussion started by: scazed
2 Replies

2. Shell Programming and Scripting

Shell script to send mail alert

HI Guys, I am writing one shell script to send the mail alert to some email id's if the file not modified in last 10 mins but its not working, I believe MTIME is null string is wrong . can you please assist me on this. script :- filename="abc.txt" echo "Filename is $filename"... (1 Reply)
Discussion started by: abhigrkist
1 Replies

3. Shell Programming and Scripting

Shell script to capture Current day ORA errors from Alert Log

Please provide Shell script to capture ORA errors from Alert Log for a given date or Current date. -Veera (1 Reply)
Discussion started by: Veera_V
1 Replies

4. AIX

How to write a script to send these alerts?

Hello AIXians :) I want to complete this task using a script. The task is: We have a file called (alerts.log), this file is receiving all new alerts from ORACLE application all the day, I want to send email to a specific mail address when this file receives all alerts that starts with... (5 Replies)
Discussion started by: Mohannad
5 Replies

5. Shell Programming and Scripting

Script to send alert if any changes are made in crontab.

Hi i want to know how can i write a script to check if any changes are made and send an alert in crontabs . i am using .ksh file extension for writing scripts. (3 Replies)
Discussion started by: honey26
3 Replies

6. Shell Programming and Scripting

PHP Mail Script Takes Hours to Send emails

guys, i have a php script that i wrote that takes hours to send emails to recipients. i can't post the content of this script in here because the script contains some very important confidential information. so my question is, why is it that when the php script runs, it runs successfully, but... (3 Replies)
Discussion started by: SkySmart
3 Replies

7. Shell Programming and Scripting

how to write a shellscript to send a mail alert to the website user based on license expiration time

hi, i am very much new to shell scripting i have a requirement that i have to develop a License Renewal Alert system that has to give a alert mail to the users before 30days of user account expiration, by checking expiration date of the user with the data base, this system will... (0 Replies)
Discussion started by: deepu_Shscripts
0 Replies

8. Shell Programming and Scripting

How to send email once a day at certain time in unix shell script

hi, i have to send an email once a day at ceratin time say 22. i have tried with date commad, but not working.:( HOUROFTHEDAY=`date +'%H'` if ; then mailx -s "Info" emailid@org.com < $ProcessStatisticsFile fi Please help me... (5 Replies)
Discussion started by: sreelu
5 Replies

9. Shell Programming and Scripting

script that reads a value and send an email on 89th day

hi all, Currently in my system a user's password expires after 90 days and the last passsword change time is stored in an attribute pwdchange date. i need a linux script that read this attribute and add 89 days and send an email that the user password is expiring the next day. i can store... (1 Reply)
Discussion started by: manankapoor
1 Replies

10. Shell Programming and Scripting

Write a shell script to find whether the first day of the month is a working day

Hi , I am relatively new to unix... Can u pls help me out to find out if the first day of the month is a working day ie from (Monday to Friday)...using Date and If clause in Korn shell.. This is very urgent. Thanks for ur help... (7 Replies)
Discussion started by: phani
7 Replies
Login or Register to Ask a Question