I wrote a Perl scirpt that doesn't quite do what I want. The script is designed to go through a log file and pull out and list all the email addresses that exist between the strings 'Enter AccountManager.createAccount' and 'Exit. Return a status code: ' followed by any single digit. If
If anything other than a digit is encountered (after 'Exit. Return a status code:
), the script should just skip that entire segment and move onto the next segment. The problem is my script matches everything between the 1st 'Enter AccountManager.createAccount' and 'Exit. Return a status code: ‘.
Source of perl script:
use strict;
use warnings;
use diagnostics;
# Declare and Assign global variables
my $log_file;
my $line;
my @value;
my $value;
print "Please enter pim log location. \n";
$log_file = <STDIN>;
chomp($log_file);
open(LOG, "< $log_file");
$line = do { local $/; <LOG> }; # Read the entire contents of the source document and assign it to the scalar 'file'.
while ($line =~ /Enter AccountManager.createAccount(.*?)Exit. Return a status code: [1-9]/gs)
{
print "-----------------------------------------------------------\n";
@value = split(/ /, $1);
foreach $value (@value)
{
if ($value =~ m/@/)
{
print "$value\n";
}
}
}
close LOG;
===================================================================
Output from execution:
C:\logs\IMS>u11.pl
Please enter pim log location.
test.log
-----------------------------------------------------------
hobo1@acme.com
-----------------------------------------------------------
hobo2dontshow@acme.com
hobo3@acme.com
-----------------------------------------------------------
hobo4@acme.com
===================================================================
Note: In the output above, the email ‘hobo2dontshow@acme.com’ should not be displayed, but it is. Anybody have any idea where my logic is wrong?
===================================================================
Input log file:
02:42:005 ad89ec AccountCreationUtil: validateISPNewEmailAccount() - Exit. Return a status code: 2
I 12:03:04:526 1d44ae9 AccountManager: Enter AccountManager.createAccount()
I 12:03:04:570 1d44ae9 AccountCreationUtil: createAccount() - Enter with AccountInfo :
emailAddress hobo1@acme.com
The retrieved MobileUserId from the created IMS account is: 178
I 12:03:13:549 1d44ae9 AccountCreationUtil: createAccount() - InstallMessageSender.sendInstallSMSUsingMTS() was successful
I 12:03:13:570 1d44ae9 AccountCreationUtil: createAccount() - Exit. Return a status code: 9
1d44ae9 AccountManager: Enter AccountManager.createAccount()
I 12:03:04:570 1d44ae9 AccountCreationUtil: createAccount() - Enter with AccountInfo :
emailAddress hobo2dontshow@acme.com
The retrieved MobileUserId from the created IMS account is: 178
I 12:03:13:549 1d44ae9 AccountCreationUtil: createAccount() - InstallMessageSender.sendInstallSMSUsingMTS() was successful
I 12:03:13:570 1d44ae9 AccountCreationUtil: createAccount() - Exit. Return a status code: a
1d44ae9 AccountManager: Enter AccountManager.createAccount()
I 12:03:04:570 1d44ae9 AccountCreationUtil: createAccount() - Enter with AccountInfo :
emailAddress hobo3@acme.com
The retrieved MobileUserId from the created IMS account is: 178
I 12:03:13:549 1d44ae9 AccountCreationUtil: createAccount() - InstallMessageSender.sendInstallSMSUsingMTS() was successful
I 12:03:13:570 1d44ae9 AccountCreationUtil: createAccount() - Exit. Return a status code: 7
1d44ae9 AccountManager: Enter AccountManager.createAccount()
I 12:03:04:570 1d44ae9 AccountCreationUtil: createAccount() - Enter with AccountInfo :
emailAddress hobo4@acme.com
The retrieved MobileUserId from the created IMS account is: 178
I 12:03:13:549 1d44ae9 AccountCreationUtil: createAccount() - InstallMessageSender.sendInstallSMSUsingMTS() was successful
I 12:03:13:570 1d44ae9 AccountCreationUtil: createAccount() - Exit. Return a status code: 7
1d44ae9 AccountManager: Enter AccountManager.createAccount()
I 12:03:04:570 1d44ae9 AccountCreationUtil: createAccount() - Enter with AccountInfo :
emailAddress hobo5dontshow@acme.com
The retrieved MobileUserId from the created IMS account is: 178
I 12:03:13:549 1d44ae9 AccountCreationUtil: createAccount() - InstallMessageSender.sendInstallSMSUsingMTS() was successful
I 12:03:13:570 1d44ae9 AccountCreationUtil: createAccount() - Exit. Return a status code: a100
If anything other than a digit is encountered (after 'Exit. Return a status code:
), the script should just skip that entire segment and move onto the next segment. The problem is my script matches everything between the 1st 'Enter AccountManager.createAccount' and 'Exit. Return a status code: ‘.
Source of perl script:
use strict;
use warnings;
use diagnostics;
# Declare and Assign global variables
my $log_file;
my $line;
my @value;
my $value;
print "Please enter pim log location. \n";
$log_file = <STDIN>;
chomp($log_file);
open(LOG, "< $log_file");
$line = do { local $/; <LOG> }; # Read the entire contents of the source document and assign it to the scalar 'file'.
while ($line =~ /Enter AccountManager.createAccount(.*?)Exit. Return a status code: [1-9]/gs)
{
print "-----------------------------------------------------------\n";
@value = split(/ /, $1);
foreach $value (@value)
{
if ($value =~ m/@/)
{
print "$value\n";
}
}
}
close LOG;
===================================================================
Output from execution:
C:\logs\IMS>u11.pl
Please enter pim log location.
test.log
-----------------------------------------------------------
hobo1@acme.com
-----------------------------------------------------------
hobo2dontshow@acme.com
hobo3@acme.com
-----------------------------------------------------------
hobo4@acme.com
===================================================================
Note: In the output above, the email ‘hobo2dontshow@acme.com’ should not be displayed, but it is. Anybody have any idea where my logic is wrong?
===================================================================
Input log file:
02:42:005 ad89ec AccountCreationUtil: validateISPNewEmailAccount() - Exit. Return a status code: 2
I 12:03:04:526 1d44ae9 AccountManager: Enter AccountManager.createAccount()
I 12:03:04:570 1d44ae9 AccountCreationUtil: createAccount() - Enter with AccountInfo :
emailAddress hobo1@acme.com
The retrieved MobileUserId from the created IMS account is: 178
I 12:03:13:549 1d44ae9 AccountCreationUtil: createAccount() - InstallMessageSender.sendInstallSMSUsingMTS() was successful
I 12:03:13:570 1d44ae9 AccountCreationUtil: createAccount() - Exit. Return a status code: 9
1d44ae9 AccountManager: Enter AccountManager.createAccount()
I 12:03:04:570 1d44ae9 AccountCreationUtil: createAccount() - Enter with AccountInfo :
emailAddress hobo2dontshow@acme.com
The retrieved MobileUserId from the created IMS account is: 178
I 12:03:13:549 1d44ae9 AccountCreationUtil: createAccount() - InstallMessageSender.sendInstallSMSUsingMTS() was successful
I 12:03:13:570 1d44ae9 AccountCreationUtil: createAccount() - Exit. Return a status code: a
1d44ae9 AccountManager: Enter AccountManager.createAccount()
I 12:03:04:570 1d44ae9 AccountCreationUtil: createAccount() - Enter with AccountInfo :
emailAddress hobo3@acme.com
The retrieved MobileUserId from the created IMS account is: 178
I 12:03:13:549 1d44ae9 AccountCreationUtil: createAccount() - InstallMessageSender.sendInstallSMSUsingMTS() was successful
I 12:03:13:570 1d44ae9 AccountCreationUtil: createAccount() - Exit. Return a status code: 7
1d44ae9 AccountManager: Enter AccountManager.createAccount()
I 12:03:04:570 1d44ae9 AccountCreationUtil: createAccount() - Enter with AccountInfo :
emailAddress hobo4@acme.com
The retrieved MobileUserId from the created IMS account is: 178
I 12:03:13:549 1d44ae9 AccountCreationUtil: createAccount() - InstallMessageSender.sendInstallSMSUsingMTS() was successful
I 12:03:13:570 1d44ae9 AccountCreationUtil: createAccount() - Exit. Return a status code: 7
1d44ae9 AccountManager: Enter AccountManager.createAccount()
I 12:03:04:570 1d44ae9 AccountCreationUtil: createAccount() - Enter with AccountInfo :
emailAddress hobo5dontshow@acme.com
The retrieved MobileUserId from the created IMS account is: 178
I 12:03:13:549 1d44ae9 AccountCreationUtil: createAccount() - InstallMessageSender.sendInstallSMSUsingMTS() was successful
I 12:03:13:570 1d44ae9 AccountCreationUtil: createAccount() - Exit. Return a status code: a100