Script to monitor job


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to monitor job
# 1  
Old 11-07-2012
Script to monitor job

Hi,
I need help to write a script to check process of job running.
If it does not run, then send email notify.

ex:
list of job: a,b,c,d,e,f

thanks,
# 2  
Old 11-07-2012
You can try something like below:-
Code:
if [ `ps -eaf | awk ' $NF ~ /^a$/' | wc -l` -eq 0 ]
then
      echo "Job: a not running" | mailx -s "Job: a not running" user@domain.com
else
      :
fi

# 3  
Old 11-07-2012
Code:
 
for process  in a b c d
do
 count=`ps -eaf |grep -v grep| grep -i '$process' | wc -l`
 if [ $count -eq  0 ]
 then
 mailx -s "$process is not running"  abc@domain.com
 fi
done

above code checks for process a b c d ....... hope it will work

---------- Post updated at 09:47 PM ---------- Previous update was at 09:44 PM ----------

bipin , can you explain how awk ' $NF ~ /^a$/' works in below code

`ps -eaf |
Code:
awk ' $NF ~ /^a$/'

| wc -l` -eq 0
# 4  
Old 11-07-2012
Quote:
Originally Posted by only4satish
Code:
 
count=`ps -eaf |grep -v grep| grep -i '$process' | wc -l`

The problem with this approach is that it will list irrelevant entries since you are grepping for just one character.

Code:
awk ' $NF ~ /^a$/'

Above awk code will take the input from ps and check if the last argument starts with a and also ends, hence we will get only relevant result.
This User Gave Thanks to Yoda For This Post:
# 5  
Old 11-07-2012
NF is a special variable meaning the number of fields. It's nicely aligned so that $NF ends up being the last field.

So it's checking the last field against the regex /^a$/. So it would accept 'a' and only 'a' for the last token.

When it's true, it prints the whole line(default action on a true statement when no code block is given for it), otherwise it does nothing.
# 6  
Old 11-07-2012
Most systems now ship with pgrep/pkill, obsoleting the more cumbersome and error prone ps|grep approaches.
Code:
for ...; do
    pgrep ... || mailx ...
done

Regards,
Alister
# 7  
Old 11-07-2012
thanks bipin.......i am new to unix .....wants to find more information on AWK.....could you please post any link/URL/PDF on AWK .......
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Script monitor website wth default tomcat script

Hi all, on our application server we have the following script that monitor the status of the website, my problem here is that i have edite the retries from 3 to 5, and the timewait to 120 second, so the script should check 5 times every 2 minutes, and if the fifth check fails it must restart... (0 Replies)
Discussion started by: charli1
0 Replies

2. Infrastructure Monitoring

Searching for Saas Monitor service which monitor my servers which are sitting in different providers

Sorry if this is the wrong forum Searching for Saas Monitor service which monitor my servers which are sitting in different providers . This monitor tool will take as less CPU as possible , and will send info about the server to main Dashboard. The info I need is CPU / RAM / my servers status (... (1 Reply)
Discussion started by: umen
1 Replies

3. Shell Programming and Scripting

How to monitor a shell script called within a script?

HIi Guys... I am in a fix.... 1st the code : Script 123.sh looks like this : ./abc # a script which is getting called in this script while true do count=`ps -ef | grep abc | wc -l` if echo "abc is running sleep 10 fi done but the process is getting checked... (5 Replies)
Discussion started by: chatwithsaurav
5 Replies

4. UNIX for Dummies Questions & Answers

Monitor a script

Hi All, In a script I would like to check whether the current running command is completed in 1 hour or not. This i want to achieve inside the same script. I don't want to use separate script to monitor my current running script. eg. pseudocode; Command1 if command1>60 mins then... (7 Replies)
Discussion started by: Vicky5
7 Replies

5. Shell Programming and Scripting

Script to monitor IOwait

Hello, I need to monitor IOwait on a server and have started this script directly on the ssh prompt. Effectively it almost does what it is supposed to do, but I have no idea how to stop it? How can I make it run it as a file based bash script? ( iostat -xk 1 /dev/sdb2 | \ perl... (10 Replies)
Discussion started by: cuantica
10 Replies

6. Shell Programming and Scripting

Monitor script

Does anyone have a monitoring script in solaris that monitors the drives in an exclosure? The script should be in /bin/bash or /bin/sh thnks again This should be for solaris 10/11 looking for something that tells me a drive is down or offline.:confused: (0 Replies)
Discussion started by: walnutpony123
0 Replies

7. Shell Programming and Scripting

Help with HD monitor script

Hi, I'm new to linux and I'm trying to compile a hard drive monitoring script. I've seen a few on the internet and I've attempted to stumble through but I'm stuck at my while/do scenario. I assigned the variable NUM then took the percentage from my output and cut the % so it would be just a... (6 Replies)
Discussion started by: crocyson
6 Replies

8. Shell Programming and Scripting

Script to Start a Job after finding the Old job completed

Hi Experts, I need a script advice to schedule 12 jobs ( SAS Codes execute back ground ). Algorithem: 1. Script checks first job. 2. Finds first job is done; invoke second job. 3. finds second job is done; invoke third job. .. Request you to please assist. (3 Replies)
Discussion started by: Jerald Nathan
3 Replies

9. UNIX for Advanced & Expert Users

load monitor script

I need help in finding a script to monitor loads for 8+ servers on a single console. The goal here is to centralize it and run the script from a single server. Can anyone help on this? Im running this script on each server to monitor the load. while true; do w | grep average | grep -v grep... (7 Replies)
Discussion started by: locabuilt
7 Replies
Login or Register to Ask a Question