Script for validation | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Script for validation

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-19-2013
sv0081493 sv0081493 is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 20 May 2014, 7:57 AM EDT
Posts: 58
Thanks: 34
Thanked 1 Time in 1 Post
Script for validation

Hi,

I need a script which do below

I have one process which runs 24*7 daily and I always has to monitor it now i want to have this automated such that if it stops at anytime we get a exception mail.

For example i use ps -ef|grep 'etl'
above command gives me the desired output.

What i am thinking is like to run this script using cron which will run in evry 5 minutes.

So i need a validation script which works like if my process stops it will throw an exception via mail and will be able to start it immediately.

Please advise.

Many thanks in advance
Sponsored Links
    #2  
Old 08-19-2013
smoofy smoofy is offline
Registered User
 
Join Date: May 2010
Last Activity: 12 August 2014, 7:44 AM EDT
Posts: 37
Thanks: 0
Thanked 6 Times in 6 Posts
I would try this:

Code:
ps -ef | grep test | grep -v grep
if [ $?==1 ] then; echo "test does not work" |mail -s "confirmation" my@address.com; fi

But I am sure there is more elegant way

Last edited by Franklin52; 08-19-2013 at 07:31 AM.. Reason: Please use code tags
The Following User Says Thank You to smoofy For This Useful Post:
sv0081493 (08-19-2013)
Sponsored Links
    #3  
Old 08-19-2013
sv0081493 sv0081493 is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 20 May 2014, 7:57 AM EDT
Posts: 58
Thanks: 34
Thanked 1 Time in 1 Post
Hi Thanks for the suggestion.

I would try this. Meanwhile could you please help me in understand the command you use below

ps -ef | grep test | grep -v grep
    #4  
Old 08-19-2013
capitanui capitanui is offline
Registered User
 
Join Date: Aug 2013
Last Activity: 24 October 2013, 2:02 AM EDT
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts

Code:
ps - ef

- lists processes

Code:
grep test

- print output lines that contain "test"

Code:
grep -v grep

- excludes the "grep test" process you ran earlier from the list
The Following User Says Thank You to capitanui For This Useful Post:
sv0081493 (08-19-2013)
Sponsored Links
    #5  
Old 08-19-2013
sv0081493 sv0081493 is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 20 May 2014, 7:57 AM EDT
Posts: 58
Thanks: 34
Thanked 1 Time in 1 Post
Hi,

I tried run your script but it is giving me below error


Code:
 
: syntax error at line 5: `fi' unexpected

Please help
Sponsored Links
    #6  
Old 08-19-2013
capitanui capitanui is offline
Registered User
 
Join Date: Aug 2013
Last Activity: 24 October 2013, 2:02 AM EDT
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts
Your script should look something like this :


Code:
#!/bin/bash

#Get the number of processes containing etl running
VAR=`ps -ef | grep 'etl' | grep -v grep | wc -l`

#Verify if VAR >= 1
if [ $VAR -lt 1 ]; then
        echo "Problem -  No etl process running" | mail -s "No process Alert" email@address.com
fi

#END

The Following User Says Thank You to capitanui For This Useful Post:
sv0081493 (08-19-2013)
Sponsored Links
    #7  
Old 08-19-2013
sv0081493 sv0081493 is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 20 May 2014, 7:57 AM EDT
Posts: 58
Thanks: 34
Thanked 1 Time in 1 Post
Excellent It worked.

Thanks for your help

---------- Post updated at 09:15 AM ---------- Previous update was at 08:01 AM ----------

Hi Could you please help me to understand the script you made
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Application Validation Script vinil Shell Programming and Scripting 1 05-05-2013 03:59 PM
Validation in shell script. ravigupta2u Shell Programming and Scripting 4 11-10-2010 03:16 AM
ISQL connectivity validation in script vikram3.r Shell Programming and Scripting 2 10-13-2010 12:06 PM
UNIX script Validation matchey Shell Programming and Scripting 1 05-07-2008 11:56 AM
Need help in file validation by shell script srichakra Shell Programming and Scripting 1 07-19-2007 02:22 PM



All times are GMT -4. The time now is 07:19 AM.