Archive for November, 2011

I've not been able to post articles recently to this blog. My free time was invested in writing code for HOPE, the CMS of Malaya Digital. Also, I made some content for the Malaya Digital website. Please visit http://www.malaya-digital.org to see what I've done. 🙂

UPDATE: http://www.malaya-digital.org is now this blog. To see HOPE in action, you can visit my personal home page at http://www.balcos.net.

Here's a Perl script that will loop to run fping, and then generate mtr and traceroute output files when an user specified packet loss threshold in the script is surpassed. Take note that this script requires fping . Here's a link to the script: icmp_check

#!/usr/bin/perl
# To stop this script, do a "touch /tmp/stopFping"
$hostToPing='www.google.com';
$packetLossThreshold=10; # Value is in percent.
$command='touch /tmp/fping.tmp';
system($command);
$command='chmod 666 /tmp/fping.tmp';
system($command);
while(!(-e '/tmp/stopFping')){
$command='fping -c 20 -q '.$hostToPing.' > /tmp/fping.tmp 2>&1';
system($command);
open(INPUTFILE, '/tmp/fping.tmp');
$packetLoss = ;
close(INPUTFILE);
chomp($packetLoss);
$packetLoss=~s/^.*\ \=\ [0-9]+\/[0-9]+\/([0-9]+)\%\,\ min.*$/$1/;
if($packetLoss ge $packetLossThreshold){
@timeStampTmp=localtime();
$timeStampFinal=sprintf("%04d-%02d-%02d-%02d%02d", $timeStampTmp[5]+1900,$timeStampTmp[4],$timeStampTmp[3],$timeStampTmp[2],$timeStampTmp[1]);
chomp $timeStampFinal;
print "We have excessive packet loss as of the moment. mtr and traceroute outputs are being generated\n";
$command='mtr -c 1 -r '.$hostToPing.' > /tmp/mtr-'.$timeStampFinal.'.txt';
system($command);
$command='traceroute '.$hostToPing.' > /tmp/traceroute-'.$timeStampFinal.'.txt';
system($command);
}
}
$command='rm /tmp/stopFping';
system($command);

Back to top