DaemonForums  

Go Back   DaemonForums > FreeBSD > FreeBSD General

FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 16th August 2008
ivanatora ivanatora is offline
Real Name: Ivan
Fdisk Soldier
 
Join Date: Jul 2008
Location: Bulgaria
Posts: 51
Default Cron won't execute a perl script

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?
Reply With Quote
  #2   (View Single Post)  
Old 16th August 2008
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Default

> $output = `ping -q -c200 xx.xxx.xxx.xxx`;

/sbin/ping

also, /(\d+?)% packet loss/ probably wont match correctly. try: /(\d+\.\d)% packet loss/
Reply With Quote
  #3   (View Single Post)  
Old 16th August 2008
18Googol2's Avatar
18Googol2 18Googol2 is offline
Real Name: whoami
Spam Deminer
 
Join Date: Apr 2008
Location: pwd
Posts: 283
Default

Quote:
Originally Posted by ivanatora View Post
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
The syntax isnt correct, perl should be replaced by an username:

Code:
*/5 * * * * ivanatora /home/ivanatora/dev/ping_stats.pl > /home/ivanatora/cronlog
__________________
The power of plain text? It can control an entire OS
Reply With Quote
  #4   (View Single Post)  
Old 16th August 2008
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default

Quote:
The syntax isnt correct, perl should be replaced by an username:
It depends, this would be the case in /etc/crontab, but not if he's using a normal user crontab.
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
  #5   (View Single Post)  
Old 17th August 2008
ivanatora ivanatora is offline
Real Name: Ivan
Fdisk Soldier
 
Join Date: Jul 2008
Location: Bulgaria
Posts: 51
Default

I'm using the regular user crontab -e.
Thank you all!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
"free" command/perl script for freebsd unixdude FreeBSD General 0 17th November 2008 09:23 PM
execute commands from xinitrc rex FreeBSD General 3 22nd October 2008 10:24 PM
Execute a command during login rex FreeBSD General 4 12th September 2008 08:09 PM
Cronjob script does not run in cron godfrank FreeBSD General 9 30th June 2008 12:41 AM
Perl Script c0mrade Programming 1 26th June 2008 05:04 AM


All times are GMT. The time now is 06:58 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick