summaryrefslogtreecommitdiff
path: root/localuserinfo
blob: 52d3a53f81a41f73890638b36d112ca0695c7dfe (plain)
  1. #!/usr/bin/perl -wT
  2. #
  3. # /usr/local/bin/localuserinfo
  4. # Copyright 2003-2007 Jonas Smedegaard <dr@jones.dk>
  5. #
  6. # $Id: localuserinfo,v 1.2 2007-02-07 10:23:08 jonas Exp $
  7. #
  8. # Print real name and/or other info for user
  9. #
  10. # TODO: Options to print other info than realname
  11. #
  12. use strict;
  13. use User::pwent;
  14. use User::grent;
  15. sub getuserinfo($) {
  16. my $username = shift;
  17. my $pw = getpwnam($username) || die "Username \"$username\" does not exist.";
  18. my ($fullname, $office, $workphone, $homephone, $other) = split /\s*,\s*/, $pw->gecos;
  19. my @addresshints;
  20. if (defined($other)) {
  21. @addresshints = grep {/^([\.[:alnum:]_-]+|\+)?@([\.[:alnum:]_-]+)?$/} split /\s+/, $other;
  22. }
  23. return ($fullname, @addresshints);
  24. }
  25. while (my $username = shift @ARGV) {
  26. my ($fullname, @addresses) = getuserinfo($username);
  27. my $localaddress = "$username\@users.kaospilot.no";
  28. print "$fullname\n";
  29. }