joker has asked for the wisdom of the Perl Monks concerning the following question:


I am making a crontab parser for the whole system.
One script (run by root) grabs the list of users:
#!/usr/bin/perl use strict; use locale; my (@users,$i); $i = 1; open(PW,"/etc/passwd") or die "Can't open //etc//passwd: $!\n"; while (<PW>) { ($users[$i]) = (split /:/)[0]; print "\n\n==========================================\n$users[$i]\n" +; system "/usr/bin/su", $users[$i], "-c /cronme"; $i = $i + 1; }

The cronme script goes through a crontab file and makes
a nicely readable calendar-type listing with comments
and such. But I expect the output to be like this:
============ User1 [Calendar] ============ User2 [Calendar] ============ User3 [Calendar]

Instead I get:
============ User1 ============ User2 ============ User3 [Calendar] [Calendar] [Calendar]


Any help ?

Replies are listed 'Best First'.
Re: Multi shell/perl output problem
by mkmcconn (Chaplain) on Jan 19, 2002 at 04:29 UTC
Re: Multi shell/perl output problem
by Kanji (Parson) on Jan 19, 2002 at 10:06 UTC

    On a different note, is there any special reason why you're making an array of all the users as you go? If not, you might want to consider making use of the getpw* family of functions, particularly getpwent...

    #!/usr/bin/perl -w use strict; $|++; # disable buffering while ( my $user = getpwent ) { print "\n\n", "=" x 40, "\n$user\n"; system "/usr/bin/su", $user, "-c", "/cronme"; }

        --k.