Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Get Out of a Dull Meeting

by hardburn (Abbot)
on Nov 30, 2004 at 20:43 UTC ( #411274=CUFP: print w/replies, xml ) Need Help??

You're sitting at a table with your cow-orkers while the head beancounter goes through his drone about how the bar on the chart for last quater is clearly larger than the bar for the quarter before, and you're starting to wonder if you can slip a certain almond-tasting chemical into the beancounter's coffee.

No worry. You covertly slip your 802.11-enabled PDA out of your pocket and browse to your web server, where you've kept the CGI below for this very situation. Not long after, you receive an SMS on your cell telling you about some emergency or other. You glance at your phone, bolt out of the room, and take an early lunch.

This CGI is for use under mod_perl2, but it shouldn't be hard to modify for regular CGI use.

The send_sms() routine gets a string containing the message to send, and returns true on success, false on failure. It's coded to use Sprint's web form for sending the message. You'll have to change it for your provider. See also: WWW::SMS.

The constant MESSAGES is an arrayref containing the messages to send. Be sure they are <= 160 chars (SMS limit). You can set which message to send with the 'emg' parameter ("emg=0" is the first message, "emg=1" is the second, etc.). The first message is used by default.

You'll need to replace the TO and FROM constants with your phone number.

#!/usr/bin/perl use strict; use warnings; use constant TO => 'xxxx'; use constant FROM => 'xxxx'; use constant MAX_CHARS => 160; use constant PAGE => ' +mpose'; use constant AGENT => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041118 +' . 'Firefox/1.0'; use constant MESSAGES => [ # Each message must be <= 160 chars (SMS l +imit) 'Run away', ]; sub send_sms { my $msg = shift; use WWW::Mechanize; my $mech = WWW::Mechanize->new; $mech->get( PAGE ); $mech->submit_form( form_name => 'composeForm', fields => { phoneNumber => TO, callBackNumber => FROM, message => $msg, characters => MAX_CHARS - length($msg), }, ); return $mech->success(); } { use Apache::RequestUtil; my $r = Apache->request; my %in = $r->args(); my $msg_num = $in{emg} || 0; send_sms( substr( MESSAGES->[$msg_num], 0, 160 ) ) or die "Couldn't send message\n"; $r->content_type( 'text/plain' ); $r->print( MESSAGES->[$msg_num] ); }

Update: Added ikegami's change to make sure send_sms() never gets a message over 160 chars.

Update (2): Added readmore tags.

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Replies are listed 'Best First'.
Re: Get Out of a Dull Meeting
by Ovid (Cardinal) on Nov 30, 2004 at 21:41 UTC

    Beautiful :)

    I once had an button on a spreadsheet that was programmed to quietly send "Call me" instant messages to my friends. When a certain annoying coworker would start yelling about his work, I'd click the button and shortly have to leave to help a customer who "called in an emergency."

    Sometimes non-geeks underestimate us.


    New address of my CGI Course.

Re: Get Out of a Dull Meeting
by ikegami (Pope) on Dec 01, 2004 at 16:32 UTC
    send_sms( substr( MESSAGES->[$msg_num], 0, 160 ) ) will ensure you didn't go over the limit accidently.

      Thanks. Updated.

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Re: Get Out of a Dull Meeting
by elwarren (Curate) on Dec 02, 2004 at 23:35 UTC
    This is great, I have been using the email interface for Sprint up until now. Sometimes email gets caught up in the queue and is not delivered immediately, I'm interested to see if this would be faster. Plus, with some hacking, we could track message delivery as well, which you can't do with the email.

    My version sends the email as soon as the page is hit/cgi is executed. I use the browser on the cellphone to hit the page, but I don't want to waste time trying to key in a message.

    I suggest adding a sleep call in there so that it's not completely obvious that you paged yourself :-)
      Or set it up before hand to send the message at a specified time. Then when in your meeting, if all is well you just ignore it, otherwise get the heck out of there. No, I am not providing code because I am at work and I've been slacking off too long already. ;-)

        No need for CGI. Simply modify the parent code to run as a command-line script, and pop this in before your meeting:

        $ at 14:22 perl

        Change 14:22 to the time of your choice. We love the UNIX at command, we does. ;-)

        require General::Disclaimer;
        s//2fde04abe76c036c9074586c1/; while(m/(.)/g){print substr(' ,JPacehklnorstu',hex($1),1)}

Re: Get Out of a Dull Meeting
by kwaping (Priest) on Apr 29, 2005 at 16:46 UTC
    Here's the same code, adapted for use with Verizon's VTEXT service. UNTESTED as server code, but now tested and working from the command line!

    Edit: Tested by commenting out server code, ran from command line. Made appropriate changes. The previous version didn't work, this current version should!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://411274]
Approved by blue_cowdawg
Front-paged by coreolyn
[marto]: Sharepoint ss a mess
[marto]: /ss/is/
[Discipulus]: yes I can imagine marto but they dont take my opinion in consideration..
[marto]: I told our client this, they spent many years and lots of consultants to try and get it to do what they wanted. They're ditching it now

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2017-06-27 09:10 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (601 votes). Check out past polls.