[Gllug] print grep var in awk shell script?
Stuart Sears
ssears at redhat.com
Fri Mar 5 13:27:29 UTC 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Tuesday 02 Mar 2004 14:59, Liam Delahunty wrote:
> 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
this adds the carriage return. Use printf instead.
> 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
...
LOGINS=`grep $username /var/log/maillog | wc`
EMAILS=`grep 'login by user '.$username /var/log/maillog |wc`
printf "user: %0 \t logins: %1 \t emails: %2\n" $username $LOGINS $EMAILS
...
or, if you want output like
user <tab> logins <tab> emails
username 150 300
you could use
printf "user \t logins \t emails\n" (do this OUTSIDE the loop)
printf "%0 \t %1 \t %2\n" $username $LOGINS $EMAILS
> But I can't work out how to get the username var to display with the
> awk. Perhaps I should be using sed too?
you could, but you don't have to...
>
> As always, thanks in advance.
- --
Stuart Sears RHCE/RHCX
Red Hat Certified Instructor
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQFASIBB1fYFK5ZLL1ERApwhAJ4jSde1v6BsXT5w+98UTlpa1YUJIQCgo36D
S+dveALYltSqkAniTpjjfsg=
=R/GA
-----END PGP SIGNATURE-----
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list