Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ps -ef for a process append to 3 logs !!

Status
Not open for further replies.

smithia6

Technical User
Aug 28, 2002
35
US
Hi I am trying my best to work it out but I now need help please.

I am looking for a process called runmqchi, using:-
ps -ef |grep runmqchi |grep -v grep

I need the script to echo out a line of text to 3 .log files if the process cannot be found, but to do nothing if it can find the process.

Can anyone help at all??

Ian
 
Hi Ian,
you can do
#!/bin/ksh
P=`ps -ef |grep runmqchi |grep -v grep`
if [ ${#P} -gt 0 ]
then
echo $P >> file1
echo $P >> file2
echo $P >> file3
fi

Boris

 
Thanks Boris

What is happening with that script is that it is echoing out the results of the ps -ef to all 3 files.
What I am after is once it does the ps -ef if it finds the process that not to appent to any logs just to exit from the script, but if it does not find the process to echo out to the script someting like "Process not found"

Regards

Ian
 
Got it sorted.

#!/bin/ksh
ps -ef |grep jkjksdbhgs |grep -v grep >/dev/null
if [[ $? -ne 0 ]]
then
echo "Process Not There" >> file1
echo "Process Not There" >> file2
echo "Process Not There" >> file3
fi

Thanks you did put me on the right track.

Regards
Ian
 
Got it sorted.

#!/bin/ksh
ps -ef |grep runmqchi |grep -v grep >/dev/null
if [[ $? -ne 0 ]]
then
echo "Process Not There" >> file1
echo "Process Not There" >> file2
echo "Process Not There" >> file3
fi

Thanks you did put me on the right track.

Regards
Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top