ajothi
April 1, 2013, 5:04pm
1
Hi,
I need help to monitoring a process using the shell script
The same output is below
oracle 32578 32577 0 Feb27 ? 00:06:47 java -cp .:lib/ant.jar:lib/ojdbc5.jar:lib/log4j-1.2.17.jar:/ORACLE_HOME/server/lib/wlfullclient.jar:/ORACLE _HOME/server/lib/weblogic.jar:Alerts.jar com.alert.wrapper.AlertPullWrapper
I am trying the below script, will keep you updated incase of any help, thanks again!
[#!/bin/ksh
pid=""
pid='ps -ef | grep "<process string>" | awk ' {print $2}''
echo $pid
if [ "$pid"="" ]
then
echo "process not running"
rsh <mail server> mailx -s "<etc etc process not running>" <mail.id>
else
echo service is ok
pid=""
fi
]
Thanks much in advance
By monitor, what are you expecting the script to do?
--ahamed
ajothi
April 1, 2013, 5:18pm
3
The script will monitor the process and should send an email if the process is stopped or killed
---------- Post updated at 05:18 PM ---------- Previous update was at 05:07 PM ----------
Hi I tried the above one
ps -ef | grep "AlertPullWrapper" | awk '{print $2}'
20031
20032
24474
It gives 3 PID's , I need to validate only with the second one 20032, how can I do that?
Yoda
April 1, 2013, 5:20pm
4
I would suggest to use pgrep
instead which is tailor made for similar requirement:
pgrep AlertPullWrapper
ajothi
April 1, 2013, 5:22pm
5
Hi,
Thanks for your reply
I tried pgrep "AlertPullWrapper" , but it did not give any results
pgrep
works on the process name, here the process is java.
Can you paste the output of ps -eaf | grep AlertPullWrapper
The 1 PID is probably that of grep
, but not sure about the other one.
--ahamed
ajothi
April 1, 2013, 5:30pm
7
Hi Please find below
# ps -eaf | grep AlertPullWrapper
oracle 20031 1 0 Jan21 ? 00:00:00 bash AlertPullWrapper.sh
oracle 20032 20031 0 Jan21 ? 00:25:19 java -cp .:lib/ant.jar:lib/ojdbc5.jar:lib/log4j-1.2.17.jar:/ORACLE_HOME/server/lib/wlfullclient.jar:/ORACLE_HOME/server/lib/weblogic.jar:Alerts.jar com.alert.wrapper.AlertPullWrapper
oracle 24741 24025 0 17:28 pts/1 00:00:00 grep AlertPullWrapper
Yoda
April 1, 2013, 5:32pm
8
That is not correct.
pgrep
can work on pattern as well. You can use -f
switch:
pgrep -f com.alert.wrapper.AlertPullWrapper
1 Like
This should give you the PID
ps -ef | awk '/java.*AlertPullWrapper/{print $2}'
--ahamed
---------- Post updated at 02:43 PM ---------- Previous update was at 02:32 PM ----------
Thanks, wasn't aware of the -f
switch
--ahamed
1 Like
ajothi
April 1, 2013, 6:03pm
10
Thank you both, working perfectly