Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

New Email Notification

by spacewarp (Pilgrim)
on Sep 07, 2001 at 10:06 UTC ( #110840=perlquestion: print w/ replies, xml ) Need Help??
spacewarp has asked for the wisdom of the Perl Monks concerning the following question:

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.

Comment on New Email Notification
Download Code
Re: New Email Notification
by dws (Chancellor) on Sep 07, 2001 at 21:18 UTC
    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?

    You might be getting throttled or dropped on the paging side. I've found that sending myself pages via email has a ~70% success rate (using AT&T).

    Instrument your code to log email sends (with timestamps). Without a record of when your script thinks it is sending email, diagnosing this is going to be difficult.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://110840]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2014-12-22 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (128 votes), past polls