summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpinyadmin/bin/lsusers39
1 files changed, 39 insertions, 0 deletions
diff --git a/pinyadmin/bin/lsusers b/pinyadmin/bin/lsusers
new file mode 100755
index 0000000..8bccd1c
--- /dev/null
+++ b/pinyadmin/bin/lsusers
@@ -0,0 +1,39 @@
+#!/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;