summaryrefslogtreecommitdiff
path: root/pinyadmin
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@omgwallhack.org>2013-01-03 22:34:20 -0800
committerJoe Rayhawk <jrayhawk@omgwallhack.org>2013-01-03 22:34:20 -0800
commit33cfec71405831fdb70bed16aa08ad7222e45b5f (patch)
tree72a052249a68b199189f3a93f19f412917ddad7d /pinyadmin
parent22bf3a8a094e7c3dc84c88877c4843cd390df602 (diff)
downloadpiny-code-33cfec71405831fdb70bed16aa08ad7222e45b5f.tar.gz
piny-code-33cfec71405831fdb70bed16aa08ad7222e45b5f.zip
pinyadmin: new lsusers command
Diffstat (limited to 'pinyadmin')
-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;