HP3000-L Archives

September 2001, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Danny A. van Delft" <[log in to unmask]>
Reply To:
Danny A. van Delft
Date:
Tue, 18 Sep 2001 08:49:17 -0600
Content-Type:
text/plain
Parts/Attachments:
text/plain (70 lines)
Perhaps it would be easier to filter out the grep line itself, as in:

ps -ef|grep cmMain | grep -v grep

Besides, your awk script won't give the expected result, even if you
change it to correctly handle WORK_PID: you cannot change an
environment variable from a son process and expect to find it in the
parent. In effect the

system("export cmmain_flag=2")

is a null operation.
You might want something like

cmmain_is_still_running=$(ps -ef|awk -v W=$WORK_PID '$2==W {print
"yep"}')

which will put yep into the variable cmmain_is_still_running if it is
with the supplied pid.

Another way is to try and sort of kill the process: kill it with a
signal 0 and the kill command will return with success (0) if the
process exists, otherwise it will fail. Don't worry, nothing else will
happen with your process:

if kill -s 0 $WORK_PID 2>/dev/null; then
echo "Still going strong"
fi

The redirect is to get rid of messages.

This only works though if you may send a signal to it, so you'll have
to be owner.


On Mon, 17 Sep 2001 13:49:08 -0500 (Central Daylight Time), Carl
McNamee <[log in to unmask]> wrote:

>I busy writing a shell script that is supposed to take down a particular
>application and then determine if the application actually quit.  If the
>application is still running then set a variable that will be used later in
>the script.
>
>The line in the script I'm having problems with is:
>  ps -ef|grep cmMain | awk '$2 != $WORK_PID {system("export
>cmmain_flag=2")}'
>When this command runs I receive the error "awk: Field $() is not correct".
>The $WORK_PID is an environment variable that was previously set to the pid
>of the current process.  What I'm trying to do with the awk command is
>filter out the grep command finding itself (which seems to happen fairly
>regularly and completely screws up the rest of the script!).  I tried
>surrounding the $WORK_DIR in quotes (single, double and tilde) but that did
>not fix the problem.
>
>Thoughts?  Comments?  Criticism?
>
>Carl McNamee
>Systems Administrator
>Billing Concepts
>(210) 949-7282
>
>* To join/leave the list, search archives, change list settings, *
>* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
>

Danny A. van Delft   [log in to unmask]

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2