Cron.daily Use of uninitialized value ERROR

Discussion in 'Server Operation' started by kisong, Mar 14, 2006.

  1. kisong

    kisong New Member

    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?
     
  2. falko

    falko Super Moderator ISPConfig Developer

    Please check line 683 of /etc/cron.daily/0logwatch.
     
  3. kisong

    kisong New Member

    This is line 683:

    if ($CheckTime <= ($FileStat[9])) {
     
  4. falko

    falko Super Moderator ISPConfig Developer

    One of these two variables hasn't been initialized before.

    This is just a warning, you can ignore it.
     
  5. kisong

    kisong New Member

    How can I initialize this variable?

    This error happens EVERY DAY!
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Therefor you will have to read / analyze the script and try to find out which variable is not cleanly initialized.
     
  7. thinktink

    thinktink New Member

    Makeshift fix: Cron.daily Use of uninitialized value ERROR

    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])) {...

    Code:
          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.
     
    Last edited: Nov 30, 2007

Share This Page