Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
Here is my script FIND_PROC=`ps -ef |grep custom |awk '{if ($8~/watchdog/)print $2}'` echo "$FIND_PROC" this works fine if the PID is short like this: root 32489 32488 0 09:05 pts/7 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2005
    Posts
    7

    Shell script using ps and awk


    Here is my script

    FIND_PROC=`ps -ef |grep custom |awk '{if ($8~/watchdog/)print $2}'`
    echo "$FIND_PROC"

    this works fine if the PID is short like this:
    root 32489 32488 0 09:05 pts/7 00:00:00 -bash

    if it is long like this:
    root 32116 1 0 08:54 ? 00:00:00 /home/progress/91c/bin/_mprshut /home/database/custom -C watchdog

    It will not read the full pid. Basically I am trying to check for a process to make sure it is running but because the pid using ps -ef is longer than 80 charcater my awk command never works.

    TIA for any help

  2. #2
    Linux Guru
    Join Date
    Mar 2003
    Location
    Wisconsin
    Posts
    1,907
    Try esacping the foward slashes \/watchdog\/

    Jeremy
    Registered Linux user #346571
    "All The Dude ever wanted was his rug back" - The Dude

  3. #3
    Just Joined!
    Join Date
    Mar 2005
    Posts
    7
    Thanks but did not work.
    From what I can tell the awk command will not read any lines over 80 characters, since the pid I am looking for is over 80 I get no return. I got it working once before, it has to do with columns or something basically I have to tell awk to read over 80.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    you might want to try grep?

  6. #5
    Just Joined!
    Join Date
    Mar 2005
    Posts
    7
    Grep does work however I have many PID's running for each database. With awk I can specify to the column what I am looking for.

    Using a shell script I am trying to verify a progress database is up and running.

  7. #6
    Linux Guru
    Join Date
    Mar 2003
    Location
    Wisconsin
    Posts
    1,907
    I don't think the problem is your string lenth, more likely, it's that the field seperator is space. You have $8, but that would be:

    /home/progress/91c/bin/_mprshut /home/database/custom

    $10 would be the watchdog.

    Jeremy
    Registered Linux user #346571
    "All The Dude ever wanted was his rug back" - The Dude

  8. #7
    Just Joined!
    Join Date
    Mar 2005
    Posts
    7
    that returns nothing,,here is the code
    FIND_PROC=`ps -ef |grep custom |awk '{if ($10~/watchdog/)print }'`
    echo "$FIND_PROC"

    I removed the $2 to show all columns....
    This is what should come back

    root 5887 1 0 14:15 pts/2 00:00:00 /home/progress/91c/bin/_mprshut /home/database/custom -C watchdog

  9. #8
    Linux Guru
    Join Date
    Mar 2003
    Location
    Wisconsin
    Posts
    1,907
    As a test, what does this do:

    awk'{print $10}'

    then try

    awk'{print $8}'

    Jeremy
    Registered Linux user #346571
    "All The Dude ever wanted was his rug back" - The Dude

  10. #9
    Just Joined!
    Join Date
    Mar 2005
    Posts
    7
    awk $10 returns nothing
    but
    awk $8 reutrns grep

    which is my script running.

  11. #10
    Linux Guru
    Join Date
    Mar 2003
    Location
    Wisconsin
    Posts
    1,907
    Does ps -ef return

    root 5887 1 0 14:15 pts/2 00:00:00 /home/progress/91c/bin/_mprshut /home/database/custom -C watchdog

    Are you running the script with the same permissions that you're running ps as? ie, if you're running the ps command as root, but the script as user, I don't know that you'll be able to see root process.

    Jeremy
    Registered Linux user #346571
    "All The Dude ever wanted was his rug back" - The Dude

Page 1 of 2 1 2 LastLast

Posting Permissions

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