[Gllug] print grep var in awk shell script?

Liam Delahunty liam at megaproducts.co.uk
Tue Mar 2 21:16:54 UTC 2004


This little script is supposed to count how many times users get mail to 
their username account or log in.

It works okay but I'd like to display it better.

#!/bin/bash
for username in `ls -l /home/spool/mail/|grep site26| awk '{print $9 }'`
do
  echo $username
  grep $username /var/log/maillog | wc | awk '{print $1 " emails"}'
  grep 'login by user '.$username /var/log/maillog |wc | awk '{print $1 
" logins"}'
done

Currently the output is:
user001
22 emails
19 logins
user002
322 emails
298 logins

really I'd like

user001    22 emails
user001    19 logins
user002 322 emails
user002    298 logins

But I can't work out how to get the username var to display with the 
awk. Perhaps I should be using sed too?

As always, thanks in advance.

-- 
Kind regards, Liam Delahunty
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list