why won't below work?
I am trying to see
a)sipfile has username of the system.
b)it will read the sipfile and do a grep function against the /etc/passwd
c)it will save that output to /tmp/result..
but my script is just hanging...
#!/usr/bin/perl -w
open(SIPFILE, "</tmp/sipfile")
or die "Couldn't find the /tmp/sipfile: $! \n";
open(RESULT, ">>/tmp/result");
my $line;
while (<SIPFILE>) {
$line = `grep $_ /etc/passwd`;
print RESULT $line;
}
close(SIPFILE);
close(RESULT);
You need a "chomp". Your $_ still has a /n which will split your shell command into two commands.
I clearly see that /tmp/sipfile has
user1
user2
user3
user4
and I see end of line($) through vi...
but when I run the script, it shows the entire /etc/passwd file in /tmp/result.
what am I doing wrong??
#!/usr/bin/perl -w
open(SIPFILE, "</tmp/sipfile");
open(RESULT, ">>/tmp/result");
while (<SIPFILE>) {
chomp;
$line = `grep \$_ /etc/passwd`;
print RESULT $line;
}
close(SIPFILE);
close(RESULT);
I dont know why but this worked.
#!/usr/bin/perl -w
open(SIPFILE, "</tmp/sipfile");
open(RESULT, ">>/tmp/result");
while (<SIPFILE>) {
chomp;
$line = `grep $_ /etc/passwd`;
print RESULT $line;
}
close(SIPFILE);
close(RESULT);
Why on earth did you add that backslash??? Now perl can't see $_ so the shell gets it. And yes it works right when you remove the backslash so perl can process it.