View Full Version : Cron.daily Use of uninitialized value ERROR
kisong
14th March 2006, 17:13
Every day, I get this error e-mail sent to my root account:
/etc/cron.daily/0logwatch:
Use of uninitialized value in numeric le (<=) at /etc/cron.daily/0logwatch line 683.
Use of uninitialized value in numeric le (<=) at /etc/cron.daily/0logwatch line 683.
Use of uninitialized value in numeric le (<=) at /etc/cron.daily/0logwatch line 683.
Use of uninitialized value in numeric le (<=) at /etc/cron.daily/0logwatch line 683.
What could be causing this error EVERY DAY?
falko
14th March 2006, 18:50
Please check line 683 of /etc/cron.daily/0logwatch.
kisong
14th March 2006, 18:59
Please check line 683 of /etc/cron.daily/0logwatch.
This is line 683:
if ($CheckTime <= ($FileStat[9])) {
falko
14th March 2006, 19:35
One of these two variables hasn't been initialized before.
This is just a warning, you can ignore it.
kisong
14th March 2006, 21:00
One of these two variables hasn't been initialized before.
This is just a warning, you can ignore it.
How can I initialize this variable?
This error happens EVERY DAY!
till
15th March 2006, 09:11
How can I initialize this variable?
Therefor you will have to read / analyze the script and try to find out which variable is not cleanly initialized.
thinktink
29th November 2007, 17:25
I believe I have found a viable solution.
My Perl skills are not strong and it's been a while since I've coded anything in Perl, so if I messed up the code please let me know.
After analyzing the script, I determined that the variable $CheckTime was not the problem. The code before the test statement always had a clause for every possible outcome for $CheckTime. I could not find a hole anywhere.
Which lead me to @FileStat.
Again, it's been a while since I've coded in Perl, but it looks like that @FileStat is populated with the stat function and I'm guessing that function takes as an input a filename (indicated by the variable used "$Archive").
I think I can safely surmise that in this case, the file referenced by $Archive does not exist and therefore @FileStat does not get properly initialized and populated by the code "stat($Archive);", leading to that very daily annoying inbox message. :mad:
My solution is to initialize the offending variable if the variable is uninitialized.
Normally, I hate modifying someone else's code. I don't know their intent, thinking process, structure, or way of doing things and I'm always afraid of stomping on their territory. I know I wouldn't like it if someone else started messing with my window apps. So in case the original author of the script reads what I did to his/her code:
I apologize, I only did it because I don't know what else to do.
The fix I've come up with is to modify the code above the line where the error is generated: if ($CheckTime <= ($FileStat[9])) {...
my @FileStat = stat($Archive);if (!defined($FileStat[9])){$FileStat[9]=0;};
The new code checks whether or not $FileStat[9] is initialized and if it isn't, initializes it with an integer zero. I have coded it to check to see if the variable isn't initialized first so that I don't (hopefully) break the original intent of the script in case the file referenced by $Archive does someday come into existence for whatever reason.
I intentionally placed the code on the same line as that of the stat($Archive) line so that if I ever have another problem with the script, the line numbers won't get shifted around and I can still use the line number with the warning/error message when I research it online.
The cron error emails have stopped since implementing this makeshift fix and I have yet to see any abnormal side effects. :)
thanks in advance for any comments.
------Edit------
I toyed with the script a bit more to find out why it was happening in the first place. I discovered that the script was trying to "stat" a broken symbolic link. Oh well, I deleted the link. No side effects as of yet.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.