Results 1 to 3 of 3

Thread: How can I test if a shell script is already running?

  1. #1
    Join Date
    Apr 2006
    Location
    Surrounded by idiots!
    Beans
    1,295
    Distro
    Kubuntu 4.10

    How can I test if a shell script is already running?

    -
    Last edited by kvonb; January 20th, 2008 at 07:52 PM.

  2. #2
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,288
    Distro
    Kubuntu

    Re: How can I test if a shell script is already running?

    Try something like:

    Code:
    #!/bin/sh
    
    REMOTE_IP=www.yahoo.com
    MY_PROCESS=foo
    CHECK_DELAY=1
    
    while true
    do
            ping -c 1 $REMOTE_IP > /dev/null
    
            if [ $? != 0 ]
            then
                    PROC_STAT=`ps -w | grep $MY_PROCESS | cut -d " " -f7`
                    if [ "${PROC_STAT}x" == "x" ]
                    then
                            echo $MY_PROCESS is not running
                    else
                            echo $MY_PROCESS is running
                    fi
            fi
    
            sleep $CHECK_DELAY
    done
    Last edited by dwhitney67; October 6th, 2007 at 08:33 AM. Reason: expanded script

  3. #3
    Join Date
    Apr 2006
    Location
    Surrounded by idiots!
    Beans
    1,295
    Distro
    Kubuntu 4.10

    Re: How can I test if a shell script is already running?

    -
    Last edited by kvonb; January 20th, 2008 at 07:52 PM.

Bookmarks

Posting Permissions

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