Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Programming & Scripting
Reload this Page Test script... anyone else do this??
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Programming & Scripting C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Reply
 
Thread Tools Display Modes
Old 05-14-2008   #1 (permalink)
AboveNBeyond
Linux Newbie
 
AboveNBeyond's Avatar
 
Join Date: Mar 2007
Posts: 114
Test script... anyone else do this??

Hello all,
I am wondering if anyone uses a script to test services to be sure they are up after say updating and rebooting a server?

For instance, if I install patches and updates and reboot the system, when I am completed I would like to run one script and have it check if services are up and running (ie: httpd, iptables, sshd, and so on)

Is this something someone does?
AboveNBeyond is offline   Reply With Quote
Old 05-14-2008   #2 (permalink)
Thrillhouse
Linux Engineer
 
Thrillhouse's Avatar
 
Join Date: Jun 2006
Location: Arlington, VA, USA
Posts: 1,202
Quote:
Originally Posted by AboveNBeyond View Post
Hello all,
I am wondering if anyone uses a script to test services to be sure they are up after say updating and rebooting a server?

For instance, if I install patches and updates and reboot the system, when I am completed I would like to run one script and have it check if services are up and running (ie: httpd, iptables, sshd, and so on)

Is this something someone does?
I'm sure there are people out there who do something like this. Just to check if they are running would be simple; diagnosing their health could be a little more challenging.

Would something like this be enough?
Code:
#!/bin/sh
HTTPD=`ps -ef | grep httpd | grep -vc grep`
SSHD=`ps -ef | grep sshd | grep -vc grep`
IPTABLES=`ps -ef | grep iptables | grep -vc grep`
echo "$HTTPD instances of httpd appear to be running."
echo "$SSHD instances of sshd appear to be running."
echo "$IPTABLES instances of iptables appear to be running."
Thrillhouse is offline   Reply With Quote
Old 05-14-2008   #3 (permalink)
AboveNBeyond
Linux Newbie
 
AboveNBeyond's Avatar
 
Join Date: Mar 2007
Posts: 114
I think that is exactly what I am looking for, I will name it, ailias it, and run it post reboot, or when ever I want to verify they are up.

Thanks for the quick response.
AboveNBeyond is offline   Reply With Quote
Old 05-17-2008   #4 (permalink)
scm
Linux Engineer
 
Join Date: Feb 2005
Posts: 977
Use can use curl to check that the http server is delivering pages.
scm is offline   Reply With Quote
Old 05-17-2008   #5 (permalink)
i92guboj
Linux Engineer
 
Join Date: Nov 2007
Location: Córdoba (Spain)
Posts: 985
As Thrillhouse already scripted, you need to take a pragmatic approach (which means that you need to check if the processes are running). That's because the OS tools will always report that the service is running if you started it, even if it segfaulted or died because of any problem.

EDITED: You can always use the OR operator || to launch the service if grep doesn't report it as running. For example:

Code:
ps -A | grep whatever || <launch whatever>
That will run a command if grep doesn't give an output (which means that the process is not running.
i92guboj is offline   Reply With Quote
Old 05-20-2008   #6 (permalink)
AboveNBeyond
Linux Newbie
 
AboveNBeyond's Avatar
 
Join Date: Mar 2007
Posts: 114
That's a nice touch too, thanks.
These tips will be very helpful.
AboveNBeyond is offline   Reply With Quote
Old 05-20-2008   #7 (permalink)
bigtomrodney
Bigtomrodinator
 
bigtomrodney's Avatar
 
Join Date: Nov 2004
Location: Sunny South-East of Ireland
Posts: 5,101
Quote:
Originally Posted by Thrillhouse View Post
Would something like this be enough?
Code:
#!/bin/sh
HTTPD=`ps -ef | grep httpd | grep -vc grep`
SSHD=`ps -ef | grep sshd | grep -vc grep`
IPTABLES=`ps -ef | grep iptables | grep -vc grep`
echo "$HTTPD instances of httpd appear to be running."
echo "$SSHD instances of sshd appear to be running."
echo "$IPTABLES instances of iptables appear to be running."
I hadn't come across that specific usage of grep before and I'm very impressed. Occasionally you do get grep returning its own process details from ps so that's a winner. Thanks Thrillhouse
__________________
In the land of the blind, the night vision users are laughing at the king

Registered Linux user #378740

New members read here / Forum Rules
bigtomrodney is offline   Reply With Quote
Old 05-20-2008   #8 (permalink)
Thrillhouse
Linux Engineer
 
Thrillhouse's Avatar
 
Join Date: Jun 2006
Location: Arlington, VA, USA
Posts: 1,202
Yeah, it's especially helpful for scripting as it prevents a lot of false positives. Humans can easily dismiss the grep.
Thrillhouse is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 12:40 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0