Script to monitor the process

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

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?

I would suggest to use pgrep instead which is tailor made for similar requirement:

pgrep AlertPullWrapper

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

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

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

Thank you both, working perfectly