Find the answer to your Linux question:
Results 1 to 2 of 2
Im using an open embeded distro and a device that used a very slimmed down linux so i need to check if a process is running on it and lots ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2009
    Posts
    18

    Grep & process question


    Im using an open embeded distro and a device that used a very slimmed down linux so i need to check if a process is running on it and lots of examples wont work on the net because of the lack of tools in the distro

    so I wrote a script

    Code:
    #!/bin/sh
    my_string="telnetd"
    echo "my script is running"
    if [ `ps -ef | grep $my_string | grep -v grep` ]; then
    {
        echo "$my_string is already running"
    }
    else 
    { 
      echo "$my_string is not running - restarting"
       cd /
      /bin/sh /usr/script/myscript.sh start
    }
    fi
    The script runs fine, but I always receive the script is not running message so the test of the process is incorrect.

    even if I put in a not test !:
    if [ `! ps -ef | grep $my_string | grep -v grep` ]; then

    Can anyone tell me what i am doing wrong?

  2. #2
    Just Joined!
    Join Date
    Apr 2009
    Posts
    18
    I think this is right

    if [ ! $? ` ps -ef | grep $my_string | grep -v grep` -eq 0 ]; then

    Can anyone confirm whether this would work for me?

    Thanks in advance

    Code:
    #!/bin/sh
    my_string="telnetd"
    echo "my script is running"
    if [ ! $? ` ps -ef | grep $my_string | grep -v grep` -eq 0 ]; then
    {
        echo "$my_string is already running"
    }
    else 
    { 
      echo "$my_string is not running - restarting"
       cd /
      /bin/sh /usr/script/myscript.sh start
    }
    fi

Posting Permissions

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