>
> I'd like to monitor a running script and if the script stops running,
> restart it and continue to monitor it. I need a little help from the
> community on the ins-and-outs of the details. But, basically I need
> someone to look at the following code/pseudo-code and give
> suggestions.
>
> 1) Check a script running.
> 2) If it's running, sleep for 30 seconds then check again.
> 3) If it's not running, restart it and continue to check after that.
>
> This is on a Red Hat box, so the first thing would be something like:
>
> While (1) {
> my $process = `ps -ef | grep <process name> | grep -v grep`;
>
> if ($process) {
> sleep 30} else {
> exec (./<process name>) or print STDERR "couldn't exec
> <process name>: $!";
> }
> }
WARNING: Totally untested, but you will get the idea
#!/usr/bin/perl -w
use strict;
my $program = "<process_name>";
my $status = `/bin/ps cat | /bin/grep $program`;
if ( length($status) > 0 ) {
sleep 30;
}
else { exec "the_process" } # start program
owen
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/