perl 修改crontab


$cronfile = "";
if(-f "/var/cron/tabs/root"){
        $cronfile = "/var/cron/tabs/root";
 
}
elsif(-f "/var/spool/cron/root"){
        $cronfile = "/var/spool/cron/root";
}
elsif(-f "/var/spool/cron/crontabs/root"){
        $cronfile = "/var/spool/cron/crontabs/root";
}else{
        print "############## EMPTY ###############/n";
        exit;
}
 
$found = 0;
open CR,"<",$cronfile || die $!;
while(<CR>){
        chomp;
        if($_ =~ /test/.pl/){
                print "########## FOUND ###########/n";
                $found = 1;
                last;
        }
}
close CR;
 
if($found == 0){
        print "########### NOT FOUND ##########/n";
        open OT,">>",$cronfile || die $!;
       
        print OT "*/5 * * * * cd /data0;perl test.pl /n";
        close OT;
}

 

你可能感兴趣的:(perl 修改crontab)