On Tue, 20 Nov 2001, Ashley M. Kirchner wrote: > I'm trying to find a solution where I can take an incoming email and > have something, an external program, parse the data as it arrives and > pipe the necessary information through to a database, say MySQL... > Basically we receive orders over the net and every order placed > generates an email. That email I would like to parse, extract the > necessary information and shove it into a database, automatically, with > no user interaction. (such script I will write of course) > > Anyone have any suggestions?
Ashley Here is a small perl script that does exactly that. I suggest you take the same approach. Works like a charm. hth charles #!/usr/bin/perl -w # invoked from /etc/aliases like this # checkpoint_pager: [EMAIL PROTECTED], "|/home/cgalpin/bin/checkpointMonitor.pl" # # or from procmail like this # | /home/cgalpin/bin/checkpointMonitor.pl # use DBI; #$host = "localhost"; #$port = 3306; $database = "checkpoint_monitor"; $user = "riaadm"; $password = "pass"; $debug =1; $dbh = DBI->connect("DBI:mysql:$database",$user, $password); if ( !defined $dbh ) { die "Cannot do \$dbh->connect: $DBI::errstr\n"; } open (LOG, ">>/tmp/checkpointMonitor.log" ) if $debug; print LOG "\nGot Message.\n" if $debug; while(<STDIN>) { print LOG $_ if $debug; if (/^$/) { print LOG "got blank line (so body is next)\n" if $debug; #my $line = <STDIN>; my ($severity, $date, $time, $host, $notification) = split(' ', <STDIN>, 5); $date =~ s@(\d{2})/(\d{2})/(\d{4})@$3-$1-$2@; print LOG "$severity, $date, $time, $host, $notification\n" if $debug; my $sth = $dbh->prepare(q{ insert into event (severity, date, host, notification) values (?, ?, ?, ?) }) || die $dbh->errstr; $sth->execute($severity, "$date $time", $host, $notification) || die $dbh->errstr; last; } } _______________________________________________ Redhat-list mailing list [EMAIL PROTECTED] https://listman.redhat.com/mailman/listinfo/redhat-list