[EMAIL PROTECTED] wrote:
>
> I am attempting to redirect the output from a system
> command to a file, however when I print it only goes to
You shouldn't be using system() for this, you should be using
back-quotes or the qx() function.
> stdout and I get 0's in the file. The first loop works
> find the second is what is failing. I have even tried
> redirecting within the system function ( system "
> command > /home/file") that doesn't work either.
>
> Any comments/suggestions are appreciated.
>
>
> sub lastlog {
> open IN, "/etc/passwd";
> open OUT, ">/home/ghansen/lastlog.txt";
> select OUT;
> while (<IN>) {
> my @passwd = split /:/;
> my $userid = ($passwd[0]);
> print "$userid \n";
> }
> open IN, "/home/ghansen/lastlog.txt" or die "Cannot
> Create Output file";
> open OUT, ">/home/ghansen/lastlog.out" or
> die "Cannot Create Output file";
> select OUT;
> while (<IN>) {
> chomp();
> $user = $_;
> $output = system "last $user | head -1";
> print "$output \n";
sub lastlog {
open OUT, '> /home/ghansen/lastlog.out'
or die "Cannot open /home/ghansen/lastlog.out: $!";
while ( my $user = getpwent() ) {
chomp( $last = ( qx(last $user) )[0] );
next if length $last == 0;
print OUT "$last\n";
}
close OUT;
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]