?
Solved

CronJob to monitor a running process

Posted on 2006-05-16
11
Medium Priority
?
267 Views
Last Modified: 2013-12-06
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!
0
Comment
Question by:ChrisSMG
  • 7
  • 4
11 Comments
 
LVL 8

Accepted Solution

by:
edkim80 earned 1000 total points
ID: 16692369
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
 

Author Comment

by:ChrisSMG
ID: 16692798
Everything but the email worked great, My servers all run Qmail. Any way to make this work?
0
 
LVL 8

Expert Comment

by:edkim80
ID: 16692953
hmm not sure about qmail.. what does the command,

alternatives --config mta

show?  is qmail an option?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:ChrisSMG
ID: 16694444
alternatives --config mta

Shows nothing.
0
 
LVL 8

Expert Comment

by:edkim80
ID: 16694634
you may have to point the qmail sendmail...

ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail
0
 

Author Comment

by:ChrisSMG
ID: 16694708
As far as permissions go, Ive got it set to 775. Is this correct? Owner is root?
0
 

Author Comment

by:ChrisSMG
ID: 16694721
would the holedctl app need to be the same owner as the bash script?
0
 

Author Comment

by:ChrisSMG
ID: 16694768
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
 

Author Comment

by:ChrisSMG
ID: 16694783
Nevermind, just a huge delay in the app starting for some reason. Beyond the scope of the question. Thanks for all your help.
0
 

Author Comment

by:ChrisSMG
ID: 16694819
Now, additionally - Say I wanted to have that email include a timestamp and a message body. How could I achieve this?
0
 
LVL 8

Expert Comment

by:edkim80
ID: 16698652
between the if and fi
i would do this...

date > date.txt
mail user@domain -s 'not running...restarting' < date.txt
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month16 days, 1 hour left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question