Find the answer to your Linux question:
Results 1 to 8 of 8
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 ...
  1. #1
    Linux Newbie AboveNBeyond's Avatar
    Join Date
    Mar 2007
    Posts
    120

    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?

  2. #2
    Linux Engineer Thrillhouse's Avatar
    Join Date
    Jun 2006
    Location
    Arlington, VA, USA
    Posts
    1,377
    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."

  3. #3
    Linux Newbie AboveNBeyond's Avatar
    Join Date
    Mar 2007
    Posts
    120
    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.

  4. #4
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Use can use curl to check that the http server is delivering pages.

  5. #5
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    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.

  6. #6
    Linux Newbie AboveNBeyond's Avatar
    Join Date
    Mar 2007
    Posts
    120
    That's a nice touch too, thanks.
    These tips will be very helpful.

  7. #7
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    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

  8. #8
    Linux Engineer Thrillhouse's Avatar
    Join Date
    Jun 2006
    Location
    Arlington, VA, USA
    Posts
    1,377
    Yeah, it's especially helpful for scripting as it prevents a lot of false positives. Humans can easily dismiss the grep.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...