Hi,
Am new and got registered only for this one thread......
Well got the same prob. but i need to differentiate if my script was invoked by rc script or by cron.....i used this but prob is that the parent of my perl script is shown as shell (bash) and not cron and that is not what i want.....how do i get around this??????
$cronpid=`ps -ef|grep cron| awk '{if(NR==1) print \$2;}'`;
$parentpid=`ps -ef | grep action.pl |awk '{if(NR == 1) print \$3; }'`;
$printst=`ps -ef| grep action.pl`;
print "Output of ps is\n$printst\n ";
print "************Cron pid is $cronpid and parentpid is $parentpid\n**************";
$printst1=`ps -ef | grep $parentpid`;
print "My parent is\n $printst\n";
if($cronpid == $parentpid){
print "This process was invoked by cron...it cannot reboot machine";
$rebootnow=2;
}
else{ print "Rebooting.....";
}
Output shown is---------------------
Output of ps is
pooja 10890 8350 0 16:43 pts/0 00:00:00 /usr/bin/perl ./action.pl
pooja 10915 10890 0 16:43 pts/0 00:00:00 sh -c ps -ef| grep action.pl
************Cron pid is 7877
and parentpid is 8350
**************My parent is
pooja 10890 8350 0 16:43 pts/0 00:00:00 /usr/bin/perl ./action.pl
pooja 10915 10890 0 16:43 pts/0 00:00:00 sh -c ps -ef| grep action.pl