Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Multi shell/perl output problem

by joker (Initiate)
on Jan 19, 2002 at 04:22 UTC ( [id://140012]=perlquestion: print w/replies, xml ) Need Help??

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.


Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://140012]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-16 20:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found