Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: parse /etc/passwd and output it as csv in hundred servers

by hippo (Bishop)
on Apr 13, 2018 at 14:23 UTC ( [id://1212813]=note: print w/replies, xml ) Need Help??


in reply to parse /etc/passwd and output it as csv in hundred servers

could I use getpwent to parse the output of $user?

No, and if all you want are the usernames you need nothing so fancy anwyay.

#!/usr/bin/env perl use strict; use warnings; my $user = <<EOT; root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt EOT chomp ($user); # as you have done $user =~ s/:.*$//mg; $user =~ s/\n/,/g; print "hostname,$user\n";

... and don't start doing master_opts => [-o => "StrictHostKeyChecking no" ] without very good reason.

Replies are listed 'Best First'.
Re^2: parse /etc/passwd and output it as csv in hundred servers
by garcimo (Novice) on Apr 13, 2018 at 16:22 UTC
    THank you what is the meaning of the two lines you added:
    $user =~ s/:.*$//mg; $user =~ s/\n/,/g;

      Same thing hippo did but more idiomatic and less readable. :P

      say join ",", "hostname", $user =~ /^([^:]+)/gm;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-23 21:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found