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 ]
|