Friday, February 27, 2009

Linux Service Check and Start Script

This script copied from somewhere checks and restarts Linux service in necessary.

======================================
#!/usr/bin/perl

# if your prgram has the string "grep" in the name or in the path
# this program won't work.

$pro2check = "service name";

open PROS, "ps -ef|grep $pro2check |";

while ($line = ){
unless ($line =~ m/grep/){
#print "it is running\n";
exit;
}
}

#print "it isn't running\n";
exec "service $pro2check start";

========================

No comments: