Monitor Process script
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > Monitor Process script




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Monitor Process script  
Neil


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-08-04 12:49 PM

I need to write a script that runs a command to bring up a number of
processes.  I can use the ps -ef command to check if these processes
are running and then the processes are taken down (there is a utility
that will return only these processes).  There should be 9 processes
running to be successful.  I need to populate a log file with an xml
response code for success or failure:

Failure:	echo ^<response code ="-2"/^>

Success:	echo ^<response code ="0"/^>

How can i run my ps -ef and do a count on the number of rows returned
and populate the log?





[ Post a follow-up to this message ]



    Re: Monitor Process script  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-08-04 12:49 PM

On 2004-10-08, Neil wrote:
> I need to write a script that runs a command to bring up a number of
> processes.  I can use the ps -ef command to check if these processes
> are running and then the processes are taken down (there is a utility
> that will return only these processes).  There should be 9 processes
> running to be successful.  I need to populate a log file with an xml
> response code for success or failure:
>
> Failure:	echo ^<response code ="-2"/^>
>
> Success:	echo ^<response code ="0"/^>
>
> How can i run my ps -ef and do a count on the number of rows returned
> and populate the log?

Pipe the output through wc -l:

num=`COMMAND | wc -l`

--
Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
 ========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License





[ Post a follow-up to this message ]



    Re: Monitor Process script  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-08-04 12:49 PM

2004-10-8, 02:14(-07), Neil:
> I need to write a script that runs a command to bring up a number of
> processes.  I can use the ps -ef command to check if these processes
> are running and then the processes are taken down (there is a utility
> that will return only these processes).  There should be 9 processes
> running to be successful.  I need to populate a log file with an xml
> response code for success or failure:
>
> Failure:	echo ^<response code ="-2"/^>
>
> Success:	echo ^<response code ="0"/^>
>
> How can i run my ps -ef and do a count on the number of rows returned
> and populate the log?

Maybe:

ps -e -o comm= | grep -c 'process-name'

Or, if you know the pids of the processes:

set -- $(ps -o pid= -p "123 124 125...")
if [ "$#" -ne 9 ]; then
echo '^<response code ="-2"/^>'
else
echo '^<response code ="0"/^>'
fi

If you're the owner of those processes, you can do:

if kill -0 12 123 345... 2> /dev/null; then
: all the pids exist
else
: some of them do not exist
fi

Depending on your system, there may be other commands (pidof,
pgrep, ps -C...).

--
Stephane





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:27 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register