ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Having a little trouble with the below perl script
Code:
#!/usr/bin/perl
#Author Leo
use Email::Address;
#use strict;
my $file = "/var/log/maillog";
my $string="75E37A371C";
open(MAIL, $file);
my @buffer =<MAIL>;
close(MAIL);
my $lines=grep(/$string/, @buffer);
#print "@lines";
my @addresses = Email::Address->parse($lines);
print $addresses[0]->address;
Not sure how to print the output, tried line as an array as well
Basically, you need to loop through the @lines array, 1 element at a time and parse that (or indeed loop through @buffer).
In your code you've already specified the Id to match on, so I don't understand your qn.
May 16 21:00:53 mspwss sendmail[32248]: 75E37A371C: to=leo@leog.in, ctladdr= (664/664)
I want to strip the email id only from this line, I am gathering data on 550 errors and I wanna check which email ids are frequently used so I can block them
I seem to be getting the below error though any idea why
Use of uninitialized value $1 in concatenation (.) or string at ./email.pl line 24.
Code
Code:
#!/usr/bin/perl
#Author Leo
use strict;
use warnings;
my $file = "maillog";
my $string="550";
open(MAIL, $file);
my @buffer =<MAIL>;
close(MAIL);
my @lines=grep(/$string/, @buffer);
#print "@lines";
foreach my $line (@lines){
#print $line
my $email = (split(/\s+/,$line))[6];
$email =~ /=([a-z]+@.*),/;
print "$1\n";
}
You need to check exactly what you're getting in each element of each of those arrays.
Try printing them to a file and have a good look; you need to know exactly what data you're dealing with before you can craft algorithms/regexes to deal with them.
If you get that error, it means there wasn't a matching email addr in that string.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.