[Gllug] print grep var in awk shell script?

Jack Bertram jack at jbertram.net
Tue Mar 2 21:39:12 UTC 2004


* Liam Delahunty <liam at megaproducts.co.uk> [040302 21:16]:
> 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
> 

How about:

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

[not tested]

if I understand your script correctly.

jack
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20040302/c9105316/attachment.pgp>
-------------- next part --------------
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list