From a73a1ebdb681a1815bd3cc87953626c9c590fdc3 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Wed, 7 Feb 2007 10:23:08 +0000 Subject: Rewrite in perl. --- localuserinfo | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'localuserinfo') 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 +# Copyright 2003-2007 Jonas Smedegaard # -# $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"; +} -- cgit v1.2.3