Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Posts
    23

    Unanswered: script to check for processes running

    Hi all,

    I need to write a script that will check what processes are currently running against a flat file containing a list of processes that should be running. For any process that is not running, I need to send an email.

    The file list will be very basic:
    proc1
    proc2
    proc3
    proc4

    What is the best way to do this? I thought about putting both sets of procs into an array and comparing them, but I quickly saw that was very, very illogical. Any hints as to how this could be done?

    I'll write it, so I'm not asking for that, I just need to be pointed in the right direction.

  2. #2
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    try this :

    for i in `cat /tmp/proglist.txt`
    do
    DUMMY=`ps -ef | grep $i | grep -v grep | wc -l`
    if [ $DUMMY -gt 0 ]
    then
    echo "Process $i is running"
    else
    echo "Process $i is not running"
    # mail to server
    # I don´t not how to do this
    # this is your part
    fi
    done
    Greetings from germany
    Peter F.

  3. #3
    Join Date
    Nov 2011
    Posts
    1
    Thanks Fal5do, it's great help.

  4. #4
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    If you can, you could add a line to the beginning each of the procs

    echo $$ >/u/procpid/proc1.pid (or some other safe place)

    Then simplify the ps command to
    ps -p`cat /u/procpid/proc1.pid`

    since you already have the process id.

Posting Permissions

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