in reply to Checking a command is running

Thanks everyone! Here is how i did it:

$RUNDBCOLD = `ps -ef | grep -v grep | grep "nscd" | awk -F/ '{print \$4}'`;
print "$RUNDBCOLD\n";
while ($RUNDBCOLD ) {
print "job is still running\n";
`/bin/sleep 2`;
$RUNDBCOLD = `ps -ef | grep -v grep | grep "nscd" | awk -F/ '{print \$4}'`;
}
print "$RUNDBCOLD finished\n";

Replies are listed 'Best First'.
Re: Re: Checking a command is running
by hmerrill (Friar) on Oct 14, 2003 at 20:56 UTC

    Glad you figured it out!

    Here's another idea - just something to think about. On my system (Red Hat Linux 9) there's an 'nscd' start/stop/status script in /etc/rc.d/init.d. So at a command prompt I can do

    service nscd status
    and if the nscd daemon is running, the return code will be zero(0) - if it's not running, the return code will be some positive number. So, you could do something like this:
    #!/usr/bin/perl -w @args = ("/sbin/service", "nscd", "status"); while (system(@args) == 0) { print "job still running!\n"; sleep 2; }
    HTH.
Re: Re: Checking a command is running
by BazB (Priest) on Oct 14, 2003 at 20:39 UTC

    As other posters have pointed out, Perl isn't shell, although it can be used that way.

    You make calls, via backticks (``) to external commands - even to call text processing tools such as awk, when you could do most of it internally with perl.

    There are modules on CPAN that allow you to look at the process list on UNIX systems (see Proc::ProcessTable)

    dragonchild has give you a good example - you should work through the way his example works and learn from it.

    Cheers

    BazB


    If the information in this post is inaccurate, or just plain wrong, don't just downvote - please post explaining what's wrong.
    That way everyone learns.