View Single Post
  #2 (permalink)  
Old 10-29-2009, 06:15 PM
jaysunn's Avatar
jaysunn jaysunn is offline
Powered By Linux
User
 
Join Date: Apr 2009
Location: 41.332032,-73.089775
OS: RHEL - OSX
Posts: 598
Thanks: 61
Thanked 78 Times in 70 Posts
Rep Power: 10
jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold
Default

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
__________________
Have a look at what I have been working on
http://www.shellasaurus.com

Last edited by jaysunn; 10-29-2009 at 06:17 PM. Reason: Gave credit to Arup my senior admin
Reply With Quote
The Following User Says Thank You to jaysunn For This Useful Post:
kumarat9pm (10-29-2009)