AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only
  • 1.  Automatic restart a process

    Posted Wed May 28, 2008 02:24 PM

    Originally posted by: SystemAdmin


    Guys,

    I am trying to create a script to automatically restart an application server process if it goes down. The problem that I am having that the script attempts a restart even if the process is running. I think the issue is on this line: if $? -eq 0 but I cannot figure it out.

    See script details below (I am also attaching the script):

    #!/bin/bash
    1. Restart UAT External Services if stopped
    #<hr />
    1. This script was created by .....
    #<hr />
    #
    RESTART="/apps/WebSphere/AppServer/profiles/fcatfcib2/bin/startServer.sh Member2
    "
    1. find Member2 pid
    ps -ef | grep Member2

    if $? -eq 0
    then
    # restart UAT External
    $RESTART
    fi
    echo $output
    #AIX-Forum


  • 2.  Re: Automatic restart a process

    Posted Wed May 28, 2008 02:35 PM

    Originally posted by: jnordtome


    If I understand correctly, you want to restart the application if it isn't running. You have the right idea, it's just that grep returns 0 if it finds something. I think you want your if statement to be "$? -ne 0". Meaning that if the process isn't running, restart it. BTW, don't forget to also exclude "grep" itself in your grep statement i.e. "ps -ef |grep -v grep |grep Member2". Your ps will sometimes pickup the grep process and ruin the whole check.
    #AIX-Forum


  • 3.  Re: Automatic restart a process

    Posted Wed May 28, 2008 03:05 PM

    Originally posted by: SystemAdmin


    That seemed to resolve the problem - I am able to now run the script as I wanted it to run.

    Thanks for the tip.

    Chrome...
    #AIX-Forum


  • 4.  Re: Automatic restart a process

    Posted Thu June 12, 2008 09:51 AM

    Originally posted by: SystemAdmin


    A neat way to grep out the grep line is to square-bracket one of the characters you're searching for, thus:

    ps -ef | grep w[h]atever
    #AIX-Forum