Register
It is currently Sun Sep 21, 2014 2:06 am

Simple service checker


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Fri Aug 27, 2010 5:17 am   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
Just need to check what services are running so something like

if ps -ef |grep /usr/bin/vsftp
echo "ok"

or if not found echo "fail"

Also need to know how to omit the grep vsftp return as ps -ef |grep /usr/bin/vsftp shows

root 1718 1 0 09:47 ? 00:00:00 /usr/sbin/vsftpd
root 2401 1811 0 12:15 pts/0 00:00:00 grep vsftp


Top
 Profile  
 PostPosted: Fri Aug 27, 2010 8:56 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Code:
if ps -ef | grep -v grep | grep -q /usr/bin/vsftp
then
  echo ok
else
  echo Fail
fi


the 'grep -v' removes the grep from the output -q switch quietens the output, if you want to see the output remove the -q

I hope that helps
DW

edit was a slight tidy up


Top
 Profile  
 PostPosted: Fri Aug 27, 2010 11:31 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
In most modern linux environments removing the 'f' option from your 'ps' command is enough to only check for the process names and not for arguments of that process. So the 'grep' should not show up anymore.
Code:
ps -e | grep -q vsftp && echo "ok" || echo "fail"


Top
 Profile  
 PostPosted: Mon Aug 30, 2010 5:25 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
Also check for the command pgrep.


Top
 Profile  
 PostPosted: Tue Aug 31, 2010 4:19 am   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
Patsie wrote:
In most modern linux environments removing the 'f' option from your 'ps' command is enough to only check for the process names and not for arguments of that process. So the 'grep' should not show up anymore.
Code:
ps -e | grep -q vsftp && echo "ok" || echo "fail"


Worked a treat many thanks


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP