#!/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);