CronJob to monitor a running process

I need a way to monitor if one of my processes is running, for the purpose of this example we'll call the process "holed".

holed resides in ~holed/bin and is started/stopped/restarted by issuing ./holedctl (start | stop | restart)

When holed is running, 604 processes run under the name holed (this is a mailing solution).

What I need to happen: Every minute, check if holed is running. If holed is not running start the process and continue monitoring it every minute.

Extra: Notify me via email when the process stops. And when its restarted.

I figured the best way would be something to do with Cron jobs. I'm fairly new to linux, but have a solid overview and understanding.

This is on Fedora Core 4 or higher.
Thanks!
ChrisSMGAsked:
Who is Participating?
 
edkim80Connect With a Mentor Commented:
yeah you can do this by cron jobs..

i would write a bash script,

#!/bin/bash

isrunning=`ps aux | grep processname | wc -l`
if [ $isrunning -eq 0 ]; then
     mail user@domain -s 'not running...restarting'
     /path/to/holedctl/holedctl start
fi

then in your crontab have an entry,
* * * * * /path/to/script

note: the ` is not a single quote, it's the character below the ~
0
 
ChrisSMGAuthor Commented:
Everything but the email worked great, My servers all run Qmail. Any way to make this work?
0
 
edkim80Commented:
hmm not sure about qmail.. what does the command,

alternatives --config mta

show?  is qmail an option?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
ChrisSMGAuthor Commented:
alternatives --config mta

Shows nothing.
0
 
edkim80Commented:
you may have to point the qmail sendmail...

ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail
0
 
ChrisSMGAuthor Commented:
As far as permissions go, Ive got it set to 775. Is this correct? Owner is root?
0
 
ChrisSMGAuthor Commented:
would the holedctl app need to be the same owner as the bash script?
0
 
ChrisSMGAuthor Commented:
My problem im noticing is that its not always running the app. I try running the script directly and i get a blank line and it doesent start the process. I noticed this machine is fedora core 3. Any ideas?
0
 
ChrisSMGAuthor Commented:
Nevermind, just a huge delay in the app starting for some reason. Beyond the scope of the question. Thanks for all your help.
0
 
ChrisSMGAuthor Commented:
Now, additionally - Say I wanted to have that email include a timestamp and a message body. How could I achieve this?
0
 
edkim80Commented:
between the if and fi
i would do this...

date > date.txt
mail user@domain -s 'not running...restarting' < date.txt
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.