Re: Help needed in searching a pattern from a mails.
- --- In email@example.com, "prasadjoshi_aol"
> Hi All,
> This is what I am doing.
> In my company, we need to download some builds from a server. These
> builds are uploaded during night at US. As soon as they upload build,
> we get a mail something like this.
> <START OF MAIL>
> From: release-eng@... [mailto:release-eng@...]
> To: release-eng [DL UNIX]
> Subject: PUNEVAULT.VXINDIA.VERITAS.COM: Replication hpux
> 5.0-2006-06-09a completed successfully!
> The source location on SVLVAULT is:
> The destination location on PUNEVAULT.VXINDIA.VERITAS.COM is:
> For more information please refer to log file at
> <END OF MAIL>
> These builds are of size near about 2 GB. If we do it mannually it
> takes around 3 to 4 hours to complete.
> Now, I want to automate this procedure. I have written a perl script
> which contacts POP3 server. Searches for mail from perticular mail ID.
> But, still I need to find
> 1. Server Name. (PUNEVAULT.VXINDIA.VERITAS.COM)
> 2. Build name (5.0-2006-06-09a)
> 3. Path on the remote server.
> I am not good at PERL scripting, I want to do it in an efficient
> manner. Can anyone help?
> Script to download the build file by taring and gziping is already
>If the mail is in a single string e.g. $mailcontents, you could parse
> Thanks and regards,
my $mailcontents = 'From: release-eng@... [mailto:release-eng@...]
sub ParseBuildInfo( $ )
# $_ is the data passed to the function.
if ( $_ =~ /\s(\S+) completed successfully.*The destination
location on (\S+) is:\s+(\S+)\s/s )
print "INFO: Server Name: $2\nBuild name: $1\nPath: $3\n";
return ( $2, $1, $3 );
print "ERROR: Unable to extract the server and directory.\n";
# Call the function and get the server/build/path info in return.
my ( $Server, $BuildName, $Path ) = ParseBuildInfo( $mailcontents );
print "$Server, $BuildName, $Path\n";
\s matches a space character (space, tab, \r, \n and \f)
\S matches a non-space character (everything bug space chars). Adding
the '+' matches at least one non-space character.
The brackets i.e (\S+) extracts the parts matched and stores them in
$1, $2 etc.
This function might drop into your current code.
Note: the code indenting might be lost as I posted this from the
groups.yahoo.com web interface.