[afnog] retrieve user account

JONAS MARTIN molajons at yahoo.fr
Tue Dec 13 15:03:15 EAT 2005


Thank Everybody for the help.

I finally write a simple shell script  which fits my need. 
The script, saved in a file named 'test',  is  : 

{ while IFS=':' read  login passwd uid gid name home bash; do
   if [ $uid -gt  1000 ]
   then
        lastlog="Never"
        lastmsg="Never"
        inboxsize="0"
      if [ -e  /var/mail/$login ]
      then
        lastlog=`stat -c %x /var/mail/$login | cut -d'.' -f1`
        lastmsg=`stat -c %y /var/mail/$login | cut -d'.' -f1`
        inboxsize=`du -sh /var/mail/$login | cut  -f1`
        homesize=`du -sh /home/$login | cut  -f1`
     fi
   echo "$login;$name;$lastlog;$lastmsg;$inboxsize;$homesize" >> result3
   fi
done ; }

I just execute it by running in the directory where the file is :
 ./test5 < /etc/passwd 2&> toto

The script has taken less 5 mn to complete.  We thought that it would take more
than 2 hours Before, to get  this information on our servers running on
Windows.

Best Regards


--- Brian Candler <B.Candler at pobox.com> a écrit :

> 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.
> 


MARTIN O. Jonas
Administrateur Réseaux et Systèmes 
Tel : +229 97 69 04 29
        +229 95 71 88 69
email : molajons at yahoo.fr
          jonas at firstnet1.com
 



	

	
		
___________________________________________________________________________ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com



More information about the afnog mailing list