#!/usr/bin/perl -w #Sample gnokii output... #2. Inbox Message (not read) #Date/time: 7/8/3 11:58:16 +1000 #Sender: +61417854586 Msg Center: +61411990017 #Text: #Test2 sub SendSMS { $Dest = $_[0]; $Text = $_[1]; $GnokiiOut = `printf "$Text" | gnokii --sendsms $Dest`; }; sub ProcessMsg { $Sender = $_[0]; $Text = $_[1]; if ( ($Text =~ /[Pp][Ii][Nn][Gg]/ ) ) { SendSMS($Sender, "PONG!"); } elsif ( ($Text =~ /[Tt][Ii][Mm][Ee]/ ) ) { SendSMS($Sender, `date`); } else { print "$Sender ... $Text\n"; }; # if }; # sub # Grab the SMS messages of fof the phone and delete them. $GnokiiOut = `gnokii --getsms SM 1 10 -d 2> /dev/null`; @GnokiiLines = split(/\n/, $GnokiiOut); # Variables used to hold the parsed SMS message. $Sender = ''; $Text = ''; $TextMode = 0; # Parse out the output from gnokii foreach $ThisOne (@GnokiiLines) { if ( ($ThisOne =~ /^[0-9]+. Inbox Message/) ) { #Inbox Message lines denot the start of a new message. if ($Text ne '') { ProcessMsg($Sender, $Text); }; # if $Sender = ''; $Text = ''; $TextMode = 0; } elsif ( ($RegSender) = ($ThisOne =~ /^Sender: ([^ ]+)/) ) { # Record the message sender for later. $Sender = $RegSender; } elsif ( ($ThisOne =~ /^Date\/time:/) ) { # Suppress Date/Time Message } elsif ( ($ThisOne =~ /^Text:/) ) { # Enter text mode upon receipt of this line. $TextMode = 1; } else { # If we're in text mode, then add this line to the text we've # received so far, otherwise log it as an unknown message. if ($TextMode) { $Text .= $ThisOne } else { print "Unknown: $ThisOne\n"; }; # else }; }; # If we have an unprocessed message, process it now. if ($Text ne '') { ProcessMsg($Sender, $Text); }; # if # We're done!