Hey kumarat9pm,
That question has come across my mind many times. I have noticed that there is really not that much forums for perl. However I have been using the following for my perl learning.
PerlMonks - The Monastery Gates
This is the most helpful site.
perldoc - perldoc.perl.org
As for using perl in my daily admin activities, I am currently working on a perl / bash shell script to locate php processes on a redhat server that cause the load to exceed 10. Once that load has been breached I am grepping for the process that caused it and attempting to terminate them. This is similar to another script that I have posted. You can see that I am still learning PERL. Most of this script is bash orientated.
Here is what I have so far. Feel free to modify and use. I have been receiving guidance from my senior admin along the way. Thanks "ARUP" hehe
PHP Code:
#!/usr/bin/perl
# Created for killing php processes which are running #
# for a long time and causing the server load to get #
# high. #
$lockfile= "/var/log/pkill.lock";
$pklog = "/var/log/pkill.log";
$kpid = "0";
if ( -f $lockfile)
{
die;
}
`touch $lockfile`;
$loadavg=`uptime |cut -d , -f 4|cut -d : -f 2`;
while ( $loadavg > "10" )
{
$kpid=`ps -eo pid,pcpu,%mem,time,cmd|grep /usr/local/bin/php |grep -v grep |sort -k4 -r |sed -e 's/^[ \t]*//' |sed -n 1p |cut -d " " -f1`;
if ($kpid) {
$pdtl =`ps auxfww |grep -v grep |grep $kpid`;
open(LOGFL,">>$pklog");
print LOGFL $pdtl;
close(LOGFL);
system("kill -1 $kpid");
sleep(20);
$loadavg=`uptime |cut -d , -f 4|cut -d : -f 2`;
} else
{
`echo "Load is not for PHP Scripts. No PHP Scripts are running currently" >>$pklog`;
$loadavg="0";
next;
}
}
if ( -f $pklog)
{
$SUBJECT="SERVER LOAD HAS REACHED 10.00 - FEW PHP PROCESSES AUTOMATECALLY KILLED";
$TO="machines\@company.com";
$MESSAGE="/usr/local/bin/messages/kill.txt";
`echo "The Server has been issued a kill to the following processes. This occured cause the system load has reached a 10.00 set threshold" >> $MESSAGE`;
`echo " " >> $MESSAGE`;
`echo " KILLED PROCESSES LIST" >> $MESSAGE`;
`echo " " >> $MESSAGE`;
`cat $pklog >> $MESSAGE`;
`mail -s "$SUBJECT" "$TO" < $MESSAGE`;
}
unlink $pklog;
unlink $MESSAGE;
unlink $lockfile;