summaryrefslogtreecommitdiff
path: root/localuserinfo
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2007-02-07 10:23:08 +0000
committerJonas Smedegaard <dr@jones.dk>2007-02-07 10:23:08 +0000
commita73a1ebdb681a1815bd3cc87953626c9c590fdc3 (patch)
tree91151c593b1a34fcbb00189814462da3e1a3c89d /localuserinfo
parentff768043d905e60b8448da3810a7cd38f8b47085 (diff)
Rewrite in perl.
Diffstat (limited to 'localuserinfo')
-rwxr-xr-xlocaluserinfo40
1 files changed, 28 insertions, 12 deletions
diff --git a/localuserinfo b/localuserinfo
index b9b7075..52d3a53 100755
--- a/localuserinfo
+++ b/localuserinfo
@@ -1,22 +1,38 @@
-#!/bin/bash
+#!/usr/bin/perl -wT
#
# /usr/local/bin/localuserinfo
-# Copyright 2003 Jonas Smedegaard <dr@jones.dk>
+# Copyright 2003-2007 Jonas Smedegaard <dr@jones.dk>
#
-# $Id: localuserinfo,v 1.1 2003-08-26 07:57:05 jonas Exp $
+# $Id: localuserinfo,v 1.2 2007-02-07 10:23:08 jonas Exp $
#
# Print real name and/or other info for user
#
# TODO: Options to print other info than realname
#
-function get_fullname_field() { getent passwd $1 | awk -F: '{print $5}' | awk -F, '{print $1}'; }
-function get_roomnumber_field() { getent passwd $1 | awk -F: '{print $5}' | awk -F, '{print $2}'; }
-function get_other_field() { getent passwd $1 | awk -F: '{print $5}' | awk -F, '{print $5}'; }
-function get_groups() { groups $1 | sed -e 's/^.*: //' -e "s/\( \+\|^\)$1\( \+\|$\)/\1/"; }
-function get_domain() { echo $1 | egrep "^@[\.[:alnum:]-]+$" | sed -e 's/@//'; }
-function get_account() { echo $1 | egrep "^([\.[:alnum:]_-]+|\+)@($gid|$maildomain)?$" | sed -e 's/@.*//'; }
+use strict;
-for uid in $@; do
- get_fullname_field $uid
-done
+use User::pwent;
+use User::grent;
+
+sub getuserinfo($) {
+ my $username = shift;
+
+ my $pw = getpwnam($username) || die "Username \"$username\" does not exist.";
+
+ my ($fullname, $office, $workphone, $homephone, $other) = split /\s*,\s*/, $pw->gecos;
+ my @addresshints;
+ if (defined($other)) {
+ @addresshints = grep {/^([\.[:alnum:]_-]+|\+)?@([\.[:alnum:]_-]+)?$/} split /\s+/, $other;
+ }
+
+ return ($fullname, @addresshints);
+}
+
+while (my $username = shift @ARGV) {
+
+ my ($fullname, @addresses) = getuserinfo($username);
+ my $localaddress = "$username\@users.kaospilot.no";
+
+ print "$fullname\n";
+}