LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 07: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, 07:29 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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 07:31 AM. Reason: |more
 
Old 05-01-2009, 08:10 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,152

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


Reply



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 10:37 AM
Shell Script : Kill a running process when another process starts ashmew2 Linux - General 3 08-20-2008 03:47 AM
mythbacken process doesn't exist doralsoral Linux - Software 1 12-12-2005 03:52 AM
launching a process if it doen't exist (Folding@HOME) Bert Linux - Software 4 11-13-2002 03:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:15 AM.

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
Open Source Consulting | Domain Registration