Hey all.. I wrote this script a while back when I couldn't leave telnets to my server open because of my firewall. It's a rather straitforward utility that I leave running in the background. Now, while this is definitely, IMO, a CUFP, it also has a problem and I'm hoping someone here can point out what I'm not seeing.

When I first run the script, it performs perfectly for about a day, but then gets more and more intermittant in its notification deliveries. Eventually, I won't receive a message from it for days, in spite of receiving dozens of emails. Any ideas?
(personal info has been anonymized)

#!/usr/bin/perl -w # Using Perl 5.005_03 on RedHat 6.2 $MAILFILE1 = "/var/spool/mail/mbox1"; $MAILFILE2 = "/var/spool/mail/mbox2"; $MAILFILE3 = "/var/spool/mail/mbox3"; $current_size1 = (stat $MAILFILE1)[7]; $current_size2 = (stat $MAILFILE2)[7]; $current_size3 = (stat $MAILFILE3)[7]; for (;;) { $newsize1 = (stat $MAILFILE1)[7]; $newsize2 = (stat $MAILFILE2)[7]; $newsize3 = (stat $MAILFILE3)[7]; if ( $newsize1 > $current_size1 ) { notify("Email Notification", "Mailbox1"); $current_size1 = $newsize1; } elsif ( $newsize1 < $current_size1 ) { $$current_size1 = $newsize1; } if ( $newsize2 > $current_size2 ) { notify("Email Notification", "Mailbox2"); $current_size2 = $newsize2; } elsif ( $newsize2 < $current_size2 ) { $current_size2 = $newsize2; } if ( $newsize3 > $current_size3 ) { notify("Email Notification", "Mailbox3"); $current_size3 = $newsize3; } elsif ( $newsize3 < $current_size3 ) { $current_size3 = $newsize3; } sleep 30; } sub notify { $user = $_[1]; $purpose = $_[0]; if ( userisonline() ) { system "echo \'***** New mail has arrived for $user *****\' | wri +te myusername"; } else { # email notice to 5140490@pager.icq.com open (SENDMAIL, "|/usr/sbin/sendmail -t") || OpenError("Sendmail" +); print SENDMAIL "To: Name <5555555\@pager.icq.com>\n"; print SENDMAIL "From: $purpose <nobody\@cwes.net>\n"; print SENDMAIL "$purpose for $user\n\n"; close (SENDMAIL); } } sub userisonline { open (WHO, "who |"); while (<WHO>) { if ( $_ =~ /myusername/ ) { close (WHO); return 1; } } close (WHO); return 0; }

Spacewarp

DISCLAIMER:
Use of this advanced computing technology does not imply an endorsement
of Western industrial civilization.

In reply to New Email Notification by spacewarp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.