Leí sobre crear un script bash que llame a mi script Perl y luego ponerlo en el rc.local,
nada de esto me ha funcionado, seguí está guía, pero nada. Muchas Gracias.
Using perl Syntax Highlighting
- #!/usr/bin/perl -w
- use warnings;
- use strict;
- use Net::POP3;
- my $ServerName = "mi server mail";
- my $UserName = "mi user ";
- my $Password = "cfsRSgfg!";
- # The program will run in an infinite loop.
- # while('TRUE')
- # {
- print "Waiting for email...\n";
- # Connect to pop3 server
- my $pop3 = Net::POP3->new($ServerName) || die "Error : Couldn't log on to server";
- # Login to pop3 server
- my $Num_Message = $pop3->login($UserName,$Password);
- my $Messages = $pop3->list();
- my ($MsgId, $MsgDate, $MsgFrom, $MsgTo, $MsgCc, $MsgSub);
- my ($MsgAttach, $MsgSize, $MsgHeader, $MsgHeadFlg, $MsgBody,$MsgNo);
- foreach $MsgNo (keys %$Messages)
- {
- my $MsgContent = $pop3->get($MsgNo);
- my $count = 0;
- $MsgHeadFlg = 0;
- $MsgBody = "";
- # print "Message No : $MsgNo\n";
- $MsgSize = $pop3->list($MsgNo);
- # print "Message Size : $MsgSize Bytes\n";
- # Process message data
- while()
- {
- # Exit if last line of mail
- if ($count >= scalar(@$MsgContent))
- {
- $MsgBody =~s/^\s*(.*?)\s*$/$1/;
- $MsgBody = "SMS de-$MsgFrom:" . $MsgBody;
- # print "$MsgBody";
- # You can only send SMS in chunks of 160 chars Max according to gnokii.
- # so breaking the body into chunks of 160 and sending them 1 at a time.
- if ($MsgSub =~ /^[+]?\d+$/ )
- {
- my @stringChunksArray = ($MsgBody =~ m/(.{1,160})/gs);
- for(my $i=0;$i<@stringChunksArray;$i++)
- {
- open(GNOKII, "| gammu --sendsms TEXT $MsgSub") || die "Error starting gnokii failed: $!\n";
- # Start gnokii and wait for the SMS body
- print GNOKII $stringChunksArray[$i];
- # Print the SMS body in 160 Char chunks
- close(GNOKII);
- sleep(10); # This is there so that the phone gets time to reset after each message. Otherwise the send fails
- }
- }
- else
- {
- print "no es un Cel";
- last;
- }
- last;
- }
- # Check if end of mail header
- if (@$MsgContent[$count] =~ /^\n/)
- {
- $MsgHeadFlg = 1;
- }
- # Proceed if message header not processed
- if (not $MsgHeadFlg)
- {
- # Split the line
- my @LineContent = split /: /, @$MsgContent[$count];
- # Check Header Info
- SWITCH:
- {
- # Get message date
- $LineContent[0] =~ /Date/i && do
- {
- $MsgDate = $LineContent[1]; # print "Date : $MsgDate";
- last SWITCH;
- };
- # Get message id
- $LineContent[0] =~ /Message-ID/i && do
- {
- $MsgId = $LineContent[1]; # print "Message ID : $MsgId";
- last SWITCH;
- };
- # Get message from
- $LineContent[0] =~ /From/i && do
- {
- $MsgFrom = $LineContent[1];
- # $MsgFrom = $1;
- $MsgFrom =~ s/"|<.*>//g;
- $MsgFrom = substr($MsgFrom, 0, 39);
- # print "From : $MsgFrom";
- last SWITCH;
- };
- # Get message to
- $LineContent[0] =~ /To/i && do
- {
- $MsgTo = $LineContent[1]; #print "To : $MsgTo";
- last SWITCH;
- };
- # Get message cc
- $LineContent[0] =~ /Cc/i && do
- {
- $MsgCc = $LineContent[1]; # print "Cc : $MsgCc";
- last SWITCH;
- };
- # Get message subject
- $LineContent[0] =~ /Subject/i && do
- {
- $MsgSub = $LineContent[1];# print "Subject : $MsgSub";
- last SWITCH;
- };
- }
- }
- else
- {
- # Process message body
- $MsgBody .= @$MsgContent[$count];
- }
- $count++;
- } #end while
- $pop3->delete ($MsgNo); # después de procesarlo: eliminarlo
- } #end foreach
- # Disconnect from pop3 server
- $pop3->quit();
- sleep(20); # Sleep for 20 seconds
- #} # end while infinito
Coloreado en 0.007 segundos, usando GeSHi 1.0.8.4
¿Me dan una mano?