LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-01-2009, 08:21 AM   #1
andrewcrawford
LQ Newbie
 
Registered: Oct 2006
Posts: 4

Rep: Reputation: 0
process checker script finds process that dnt exist


Hello all,

I have a script that i am using ot check if a process is running then echo out if it is and echo and email if it is down.

However when i run it witha valid process it says process is running when i run it with just anything like say abcdefg it says it is running but there is no such process so i aint sure what i ave done wrong on the script.

#!/bin/sh

if ps ax | grep -v grep | grep -w $1 > /dev/null
then
echo "$SERVICE is running"
else
echo "$SERVICE is not running"
echo "$SERVICE is not running!" | mail -s "$SERVICE down" root
fi

Thanks

A
 
Old 05-01-2009, 08:29 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Quote:
Originally Posted by andrewcrawford View Post
if ps ax
The outcome of this does not automagically make a process a service...


Quote:
Originally Posted by andrewcrawford View Post
echo "$SERVICE is running"
This variable wasn't declared as in 'SERVICE=$1'.


Quote:
Originally Posted by andrewcrawford View Post
if ps ax | grep -v grep | grep -w $1 > /dev/null
On GNU/Linux you may want to use 'pgrep' instead.


Quote:
Originally Posted by andrewcrawford View Post
echo "$SERVICE is not running!" | mail -s "$SERVICE down" root
Are you sure you want to reinvent the wheel and not use something like 'monit'?

Last edited by unSpawn; 05-01-2009 at 08:31 AM. Reason: |more
 
Old 05-01-2009, 09:10 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,832

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
For a light-weight solution, adapting the script to simply use the return code from pgrep should work fine.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding the Process ID of a Process While Initiating the Process senthilmuthiah Linux - Newbie 7 04-02-2009 11:37 AM
Shell Script : Kill a running process when another process starts ashmew2 Linux - General 3 08-20-2008 04:47 AM
mythbacken process doesn't exist doralsoral Linux - Software 1 12-12-2005 04:52 AM
launching a process if it doen't exist (Folding@HOME) Bert Linux - Software 4 11-13-2002 04:02 PM


All times are GMT -5. The time now is 02:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration