#!/usr/bin/perl use strict; use warnings; use Getopt::Long::Descriptive; my @users = (); my @pwent = (); my ($opt, $usage) = describe_options( '%c %o', [ "name|n", "sort by name"], [ "date|d", "sort by date"], [ "reverse|r", "reverse sorting"], [ 'help', "print usage message and exit" ], ); if ( $opt->help ) { print($usage->text); exit; }; while( @pwent = getpwent()) { if( $pwent[2] >= 1000 && $pwent[2] < 65534 ) { push( @users, "$pwent[0]\n" ); }; }; # sort by date kinda done by default # maybe sort by time since last password change in /etc/shadow? if ( $opt->name ) { @users = sort( @users ); }; if ( $opt->reverse ) { @users = reverse( @users ); }; print @users;