1752790 Members
5923 Online
108789 Solutions
New Discussion юеВ

Re: search pattern issue

 
SOLVED
Go to solution
Hakki Aydin Ucar
Honored Contributor

Re: search pattern issue

>Horia: ($line =~ m/$pattern{0}/ )

only the first pattern working, others not working, problem is why perl picks up all pattern they are not even on the $pattern values ?

Regards,
Hakki Aydin Ucar
Honored Contributor

Re: search pattern issue

Sorry for points assigned in reverse posts but all belongs to you eventually.
Thanks, the problem solved apparently now, but another problem ,if patterns don t match , still written into OUTPUT file ??

is it weird ? something is missing in the loop ?
Horia Chirculescu
Honored Contributor

Re: search pattern issue

There should be nothing in the output file if nothing to match...

What exactly do you get in the output file in this case?

Horia.
Best regards from Romania,
Horia.
Horia Chirculescu
Honored Contributor

Re: search pattern issue

.. and do not forget to close (OUT) when exit for (not pasted in my example code)
Best regards from Romania,
Horia.
Horia Chirculescu
Honored Contributor

Re: search pattern issue

#!/usr/bin/perl
@users=`cat /etc/passwd|awk -F: '{print \$1}'`;
my $K;
open(OUT,">>/tmp/LogonOutput");

for ( $K = 1; $K <= @users; $K++ )
{
open(IN,"/tmp/UserLogin");
while ($line=)
{
$pattern = "$users[$K-1]" ;


if ( $line =~ m/$pattern{0}/ ) {
print "$pattern equal to $line\n";
print OUT "$line\n";
}
}
close(IN);

}

close(OUT);
Best regards from Romania,
Horia.
Hakki Aydin Ucar
Honored Contributor

Re: search pattern issue

>Horia:There should be nothing in the output file if nothing to match...
What exactly do you get in the output file in this case?

this is from output file:
LOGIN Sep 17 2010 18:03:09
root Sep 17 2010 18:03:24
student Sep 20 2010 13:55:45


LOGIN and root are not in the @users list but goes to output file ??
Hakki Aydin Ucar
Honored Contributor

Re: search pattern issue

Horia,

I tried to change environment and seems its working now , so my test server has some problems by Perl sources ??
I will notify the solution after completed tests.
Thanks
Hakki
Horia Chirculescu
Honored Contributor
Solution

Re: search pattern issue

I believe user "root" should be in /etc/passwd so will be present also in @users list.

This could be true also for the "student" user.

Looks strange the presence of LOGIN.

grep LOGIN /etc/passwd?


Can you attach the file /tmp/UserLogin ?

Horia.
Best regards from Romania,
Horia.
Horia Chirculescu
Honored Contributor

Re: search pattern issue

>I tried to change environment

What exactly did you changed in the env. ?

Horia.
Best regards from Romania,
Horia.
Hakki Aydin Ucar
Honored Contributor

Re: search pattern issue

>Horia:I believe user "root" should be in /etc/passwd so will be present also in @users list.

No, I took it out from passwd file with "grep -v"

I meant another server with environment change.

Last script is here (working great now!)
@users=`cat /etc/passwd|awk -F: '{print \$1}'|grep -vE 'root|nwauto|daemon|bin|sys|adm|uucp|lp|www|webadmi
n|hpdb|informix|nuucp|smbnull|mysql|nwcron|goglobal|alop|trop|dbadmin|c7op|sysadmin`;
my $K;
open(OUT,">>/tmp/LogonOutput");
for ( $K = 1; $K <= @users; $K++ )
{
open(IN,"/tmp/UserLogin");
while ($line=)
{
$pattern = "$users[$K-1]" ;
if ( $line =~ m/\b$pattern{0}/ ) {
print "$pattern equal to $line\n";
print OUT "$line";
}
}
close(IN);
}
close(OUT);