Why

My co-workers and I are occasionally forgetting to turn our Nextel phones on in the morning, and thus people have trouble reaching some of us for the 1st 2 hours of every Monday morning. Being admins, this is not a good thing. As I am occasionally guilty, I wrote this script to check to see if our Nextels are on before the boss reminds us, or something bad happens. To make the pages less annoying, I had it pull and send a stock price, too.

How it works

It reads the nextel number and SMTP address from a reads from a file, and does a group page. It then waits 45 seconds (I've found that 20 is plenty) and checks if each of the pages have been delivered individually. If not, it fires an e-mail to the specified SMTP address.

What you need

  1. A SMTP server to point to
  2. A file called pageme.txt conatining the phone numbers and SMTP addresses of those who want to use the script. in the format "phone#,SMTP address", one person per line. (E.g. 6175551212,monkman@nutty.com)

Code

# Opens pageme.txt, and sends a group page to those listed. # It then sends an e-mail to those that don't get the page. use strict; use LWP::Simple; my (%phonehash,$key); open IN, "<pageme.txt" or die "Can't open Phone list!"; while (<IN>){ chomp; my ($phone,$email)=split(/,/); $phonehash{$phone}=$email; } close IN; my $STT = get "http://moneycentral.msn.com/scripts/webquote.dll?iPag +e=qd&Symbol=stt"; my ($price)=$STT=~/Last<\/TD><TD ALIGN=RIGHT NOWRAP><B>&nbsp;(\d+.\d ++)/; my $phonelist=join('%20',(sort keys %phonehash)); my $doc = get "http://messaging.nextel.com/cgi/iPageExt.dll?sendPage&o +neWayPTNs=$phonelist&from=Perl&subject=Phone Check&message=Good Morni +ng! STT is currently $price"; my ($check)=$doc=~/"claimCheck" value="(\d+)"/; print "sent page (claim check: $check)\nwaiting 45 seconds to check re +ceipt...\n"; for (1..45){ sleep 1; print "$_." } foreach $key (sort keys %phonehash){ my $num=1; my $doc2= get "http://messaging.nextel.com/cgi/iPageExt.dll?pageStat +us&claimCheck=$check&phone$num=$key&StatusCheck=1"; if ($doc2=~/Delivered/){ print "Delivered OK"; }else{ print OUT "Coudn't deliver page. Sending e-mail notification\n"; &SendEmail($phonehash{$key},$key); } $num++; } sub SendEmail { use Net::SMTP; my ($email,$phone)=@_; my $smtp = Net::SMTP->new('server'); $smtp->mail($ENV{USER}); $smtp->to("$email"); $smtp->data(); $smtp->datasend("From: Perl\n"); $smtp->datasend("Subject: Nextel\n"); $smtp->datasend("\n"); $smtp->datasend("Your phone (#$phone) appears to be off. You will + get a test page when you turn it on.\n"); $smtp->dataend(); }

Update: mPageExt.dll was changed to ipageExt.dll by Nextle recently. Be sure to update accordingly (the script above was already corrected).

-OzzyOsbourne


In reply to Is your Nextel on? Why not check? by OzzyOsbourne

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.