I've set up a little script, written in Perl that keeps stats of ping timeous. I want to schedule it to run every 5 minutes.
This is my crontab:
Code:
*/5 * * * * /usr/bin/perl /home/ivanatora/dev/ping_stats.pl > /home/ivanatora/cronlog
You can see that I've even added the full path to the perl interpreter in case of $PATH misunderstandings...
And here is the script:
Code:
> cat ping_stats.pl
#!/usr/bin/perl
$dump = "/home/ivanatora/stats_ping_packet_loss.log";
open (FH, ">>", $dump) or die "$!";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$mon++;
$year += 1900;
$time = sprintf("%02d/%02d/%4d %02d:%02d:%02d", $mday, $mon, $year, $hour, $min, $sec);
$output = `ping -q -c200 xx.xxx.xxx.xxx`;
if ($output =~ /(\d+?)% packet loss/){
print FH "$time : $1% loss\n";
print "$time : $1% loss\n";
}
close (FH);
If I run the script from command line it works. However cron appears to 'run' it, but nothing happened. I'm tracking the process list with `ps` and I shuld see the 'ping' process for a long time, but there is nothing. Also the output file is not written at all, nor the stdout pipe.
I see this in /var/log/cron:
Code:
Aug 16 15:05:00 jupiter /usr/sbin/cron[1535]: (ivanatora) CMD (/usr/bin/perl /home/ivanatora/dev/ping_stats.pl > /home/ivanatora/cronlog)
What does that mean? It says it had run it, but nothing?
I'm about to say again that the script is working if run manualy, or even working in Linux crontab.
What am I doing wrong in FreeBSD?