I have a perl script which Im planning to run every minute. I have set the cron job as
* * * * * PATH= /usr/local/bin:/usr/bin:/usr/sbin:/usr/lib; perl /dm2/www/html/isos/pre5.3/autoDownload.pl
I assume the script is executing every minute only because I see a entry like below when I do cat cron in /var/log/
Jul 26 04:57:01 dmvbu-build crond[773]: (root) CMD (PATH= /usr/local/bin:/usr/bin:/usr/sbin:/usr/lib; perl /dm2/www/html/isos/pre5.3/autoDownload.pl)
Jul 26 04:58:01 dmvbu-build crond[687]: (root) CMD (PATH= /usr/local/bin:/usr/bin:/usr/sbin:/usr/lib; perl /dm2/www/html/isos/pre5.3/autoDownload.pl)
But my problem is I have statements like
print LOG "connecting to website\n"
where LOG is a file descriptor to a file named log.txt which is located at dm2/www/html/isos/pre5.3/ (same place as autoDownload.pl)
But I dont see this log.txt file updating with new informations after I see the entry in the cron log file But I see this file updating when I run the code manually
You have to remove the extra space after the
=
inPATH
.The
cron
line should beNote the lack of a space after the
=
and the lack of a semicolon beforeperl
.Its much easier to debug a program when you have the output/errors. You should also use an absolute path to perl in either the top of you script or on the cron line. You should then be able to get rid of any
$PATH
messyness.Try adding a
MAILTO
line to cron above your process.or alternatively logging the cron output to a file to watch for errors. Get rid of
/usr/bin/perl
in the crontab by making sure its the 1st line of the script#!/usr/bin/perl
.Provide the absolute Path to the logfile (
/dm2/www/html/isos/pre5.3/log.txt
instead of justlog.txt
) whenopen()
-ing, otherwise you have to ensure that the "current working directory" of cron is where you want it to be.Also check that the user under which this command is executed has write-permissions to the file.