[afnog] retrieve user account

Brian Candler B.Candler at pobox.com
Fri Dec 9 12:14:40 EAT 2005


On Fri, Dec 09, 2005 at 04:22:07AM +0100, JONAS MARTIN wrote:
> I'm a senior system administrator in an ISP entreprise. We're used LINUX DEBIAN
> and Sendmail on our mail server. For the annual point to our comptability
> service, I must provide informations on users accounts such as : login, full
> name,last access to the server, forward address email, number of messages, disk
> espace usage, ...
> I would like to know if there is any package which can help me to retrieve all
> those informations for all users created on the server and save in directly in
> a file .csv for example.
> I know the command "finger" but I must execute it many times for the 245 users
> on the servers.
> Thanks for any suggestion

You probably just want to write a little script, in sh or perl or awk or
whatever you're comfortable with. It will need tweaking based on what kind
of Unix you're using.

In shell, a simple starting point is:

#!/bin/sh
IFS=":"
cat /etc/passwd | while read username password uid gid gecos home shell; do
  echo "---- $username ----"
  finger $username
done

It's still up to you to parse the 'finger' output. However using this as a
starting point, you can run additional commands for each user, such as

  echo "Disk space: $(du -s $home)"

to find the disk space usage.

Many people run scripts like this every night, to find out who are the top
10 or 20 disk space hogs, and give them a telling off :-)

Shell scripts are pretty limiting. If you want to learn something more
flexible, you might want to look at Perl (ugly but ubiquitous) or Ruby
(lovely but less well known)

Regards,

Brian.



More information about the afnog mailing list