script to monitor process running on server and posting a mail if any process is dead

Hello all,
I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted.

Thanks in advance

Regards,
pradeep kulkarni.
:mad:

Hello all,
can any body help me with a script that will check every day for process running on UNIX server and Post a mail if any of the process has aborted or stoped. It is really urgent and i 'm new to unix.
Plz some one help me on this at the earliest.

Thanks in advance,
Regards,
:wink: Pradeep Kulkarni.

First, read the rules - no double posting or bumping post to get an answer.

Next, these forums are meant to help those that help themselves. Meaning you start writing the script and when you get to a problem, post it and we assist in solving your problem. Just look at how you normally would solve this problem from the command line and put it into a file which you then set to executable.

hello,
i have posted the mail to make my problem clear. i know how to check it through command line using ps command. but i dont know how i get the status of the process and after that when i redirect the output to a file how do i filter it for the aborted/ stoped processes and send a mail. i have tried writing script but i did not work that why i have ask for help. thanks for you suggestion...i would be thankful if any onne could help me with this script the giving advices.

regards,
Pradeep Kulkarni.

I don't see anything attached.

Try a copy/paste into the window where you type this message.
Use code with square brackets

#this is my script
exit

hi guys,
i'm back with a small problem.
i have now written a script that will grep for a process and will notify me if not running.
[#!/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
]
now i'm have a problem in the mailing section.
can any one tell me how i can redirect the output to a file and send it via mail if the process i'm greping is not runnning. i tried the above syntax and failed.

And one more help how can i find the parent process that aare running so that i can make a list of those important process.

kindly some one look into this and reply at earliest.

Regards,
Pradeep Kulkarni

Instead of
rsh <mail server> mailx -s "<etc etc process not running>" <mail.id>
try
mailx -s "<etc etc process not running>" yourID@yourdomain.xxx < /dev/null

Change yourID and yourdomain.xxx to your userid and domain name.

hi RTM,
Thanks for the update it works, one small help how can i liist all the parent process running on a unix machine, so that i can grep for only those.
i have all unix machine ( HPUX, AIX, SUN and IRIX)can you help me on this.

Thanks in advance.

Regards,
Pradeep Kulkarni.

To know the parent process use:

ptree [PID]

/usr/bin/ptree [ -a ] [ [ pid | user ] ... ]

ptree Print the process trees containing the specified pids
or users, with child processes indented from their
respective parent processes. An argument of all digits
is taken to be a process-id, otherwise it is assumed
to be a user login name. Default is all processes.

hi,
i have a new problem, i had problem with time on my aix machine the date had changed to 2022 year, now i want to find all the files in the dir and sub dir that has the time stamp with year 2022, can any one help me on this. i tried with find command but could nott formate an expression.

Kindly help me.
Thanks in advance
Pradeep Kulkarni.

Pradeep,

This new problem is not in any way related to your 'process' post.

Advise you to start a new thread for a new problem (always).

Vino

hi,

the script that u had posted

#!/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

will always return a pid since grep is a process, ( u will not receive process not running message even though the actual process isnt running) need to trip off the process grep when checking for other process pids and what if the other user has the same process, u would end up with pids that are not under your control.

you can try this,
ps -ef | grep <user> | grep -v grep | grep <process string> | awk '{print $2}'

hi
while i tried for to run script
[#!/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
]

i got errors that are :
./pname.sh: line 1: [#!/bin/ksh: No such file or directory
./pname.sh: line 3: {print: command not found

process not running
./pname.sh: line 12: ]: command not found

i m new in linux environment and need ur favour. plz how to compile this script.

actually i need a command fron that maps process name to process id.
thx.

Hi, This is the answer to your query.

bash-3.00$ vi ProcessMonitoring.sh
#!/bin/ksh
puser=1
for name in `cat perf_listfile`
do
puser=`ps -ef | grep $name |grep root | awk ' {print $1}'`
#puser=`ps -ef | grep "jogi" |grep root | awk ' {print $1}'`
echo $puser
echo $pid
if [ $puser -eq root ]
then
echo "successful"
else
echo "This is an auto-generated mail for Process Monitoring Error. Process $name not running. From : Error Monitoring Process." | mailx -s "Process Monitoring Error : $name not running" centurygalactus@gmail.com
fi
done