#!/usr/bin/perl # vi:ts=4 sw=4 et: use strict; use warnings; #> global variables #> ---------------------------------------------------------------------------- my $file = '/etc/passwd'; #> sub routines #> ---------------------------------------------------------------------------- sub parse_passwd { my $passwdfile = shift; my %passwd = (); open my $fh, '<', $passwdfile or die "$passwdfile: open(ro) failed: $!\n"; while ( my $line = <$fh> ) { chomp $line; my ( $user, $pw, $uid, $gid, $com, $home ) = split m{:}, $line; if ( $uid >= 1_000 and $user =~ m{\A[A-Za-z0-9]+\z} and !exists $passwd{$user} ) { $passwd{$user} = { gid => $gid, uid => $uid, comment => $com, homedir => $home, }; } } close $fh; return \%passwd; } sub print_passwd { my $hash_r = shift; for my $user ( keys %$hash_r ) { # nur user listen, die nicht gid==100 sind if ( $hash_r->{$user}->{gid} != 100 ) { printf "%s: %d %d %s %s\n", $user, @{$hash_r->{$user}}{ qw( uid gid comment homedir) }; } } } #> main script #> ---------------------------------------------------------------------------- print_passwd( parse_passwd( $file ) ); __END__