Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old November 18th, 2000, 04:55 PM
chris22 chris22 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Posts: 63 chris22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
This is kind of complicated and I hope I'm explaining it properly.

What I'm trying to do is create a set of scripts attached to an alias in sendmail so that I can get the local weather on my 2-way pager.

So if I send an email to say getweather@foo.com, sendmail will route the message to a perl script that gets the current weather information from the National Weather Service METAR data, formats it into an e-mail and sends it back to my pager.

Does anyone know of a script that is currently available or have any suggestions? I already know how to get sendmail to direct messages to a PERL script and I can get that script to e-mail a message back to me. The problem I'm having is getting the data from METAR.

Any help will be greatly appreciated.

Thanks,

Chris.

[This message has been edited by chris22 (edited November 18, 2000).]

Reply With Quote
  #2  
Old November 19th, 2000, 02:40 PM
Pepe Pepe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 71 Pepe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by chris22:
... sendmail will route the message to a perl script that gets the current weather information...[/quote]

Could you please tell me how do you do that. I'm currently using script for reading email POP3 account which is run by cron command. I wonder if there is better way?

I have some scripts that extract information from other pages, but what is METAR ?


Reply With Quote
  #3  
Old November 19th, 2000, 04:10 PM
chris22 chris22 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Posts: 63 chris22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
The script I'm using is a modified version of mailback ( http://www.cynicism.com/~derek/mailback/ ).

What you want to do is set up an aliases in sendmail that redirects incoming messages to this perl script.

e.g.

admin: "|/mail/mailback.pl"

Of course, make sure you run newaliases after making this change. Also, make sure your mailback.pl script is executable.

Also, create a file in the same dir as you put the script called message. What ever you put in that file will be the content of the returned message.

METAR is basically an hourly weather report that is posted to the NOAA website in plain text format (see http://weather.noaa.gov/pub/data/ob...metar/stations/ ). Information about decoding them is here.

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
#!/usr/bin/perl
$path = "/mail";
$logging = "yes";
$sendmail = "/usr/sbin/sendmail";
$includeOriginal = "yes";
undef $/;
$incoming = <>;
($inHeader, $inMessage) = split(/nn/,$incoming,2);

$time = localtime(time);

@headers = split(/n/,$inHeader);
foreach $header (@headers) {
($junk, $mail{'Subject'}) = split(/: /,$header) if $header =~ m/^Subject:/;
($junk, $mail{'From'}) = split(/: /,$header) if $header =~ m/^To:/;
($junk, $mail{'To'}) = split(/: /,$header) if $header =~ m/^From:/;
($junk, $mail{'To'}) = split(/: /,$header) if $header =~ m/^Reply-To:/;
}
if ($mail{'From'} =~ m/@/) {
($id,$junk) = split(/@/,$mail{'From'});
}
else {
$id = $mail{'From'};
}

&checkExceptions;
&log("autoresponse") if $logging;

# open MESSAGE, "$path/message-$id";
open MESSAGE, "$path/message";
$mail{'Message'} = <MESSAGE>;
close MESSAGE;

&sendMessage;

sub sendMessage {
$sendmailMessage = "From: $mail{'From'}nDate: $timenTo: $mail{'To'}nSubject: Re: $mail{'Subject'}nn$mail{'Message'}";
if ($includeOriginal) {
$inMessage =~ s/^/>/g;
$inMessage =~ s/n/n>/g;
$inMessage = "nYou wrote:nn" . $inMessage;
$sendmailMessage = "From: $mail{'From'}nDate: $timenTo: $mail{'To'}nSubject: Re: $mail{'Subject'}nn$mail{'Message'}$inMessage";
} else {
$sendmailMessage = "From: $mail{'From'}nDate: $timenTo: $mail{'To'}nSubject: Re: $mail{'Subject'}nn$mail{'Message'}";
}
open (MAIL , "|$sendmail -t");
print MAIL $sendmailMessage;
print $sendmailMessage;
close (MAIL);
}

sub checkExceptions {
local $realSender = $mail{'To'};
$realSender =~ s/.*<(.*)>/$1/;
open (EXCEPTIONS, "$path/exceptions-$id");
foreach $person (<EXCEPTIONS> ) {
chop($person);
if ($realSender eq $person) {
&log("excepted");
exit;
}
}
}

sub log {
$action = shift @_;
open (LOG, ">>$path/log");
print LOG "$time : $action to $mail{'To'} for $mail{'From'} regarding $mail{'Subject'}n";
}
[/code]

[This message has been edited by chris22 (edited November 19, 2000).]

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Perl + Sendmail


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway