If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > script to check for processes running

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-14-03, 13:16
bgame bgame is offline
Registered User
 
Join Date: Nov 2003
Posts: 23
script to check for processes running

Hi all,

I need to write a script that will check what processes are currently running against a flat file containing a list of processes that should be running. For any process that is not running, I need to send an email.

The file list will be very basic:
proc1
proc2
proc3
proc4

What is the best way to do this? I thought about putting both sets of procs into an array and comparing them, but I quickly saw that was very, very illogical. Any hints as to how this could be done?

I'll write it, so I'm not asking for that, I just need to be pointed in the right direction.
Reply With Quote
  #2 (permalink)  
Old 11-14-03, 16:01
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
try this :

for i in `cat /tmp/proglist.txt`
do
DUMMY=`ps -ef | grep $i | grep -v grep | wc -l`
if [ $DUMMY -gt 0 ]
then
echo "Process $i is running"
else
echo "Process $i is not running"
# mail to server
# I donīt not how to do this
# this is your part
fi
done
__________________
Greetings from germany
Peter F.
Reply With Quote
  #3 (permalink)  
Old 11-10-11, 16:08
Muhammadd Muhammadd is offline
Registered User
 
Join Date: Nov 2011
Posts: 1
Thanks Fal5do, it's great help.
Reply With Quote
  #4 (permalink)  
Old 11-10-11, 17:12
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
If you can, you could add a line to the beginning each of the procs

echo $$ >/u/procpid/proc1.pid (or some other safe place)

Then simplify the ps command to
ps -p`cat /u/procpid/proc1.pid`

since you already have the process id.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On