1827723 Members
2752 Online
109968 Solutions
New Discussion

awk question

 
SOLVED
Go to solution
justin_83
Advisor

awk question

I have my systems e-mail system info for me to monitor. I have it send me the info from the sulog but I would also like to include the users name.
using the /var/adm/sulog and /etc/passwd I want the output to look like:

SU 04/16 09:11 + th mylogin-root Joey Toes,,,

all on one line keep the e-mail short.

Also, I have attached the script I use please make suggestion or add more to monitor....

I'm running HPUX 11.0 on N,L&K class servers..
2 REPLIES 2
John Poff
Honored Contributor
Solution

Re: awk question

Hi,

Here is one way to do it, probably not the best way:

grep $SUDATE /var/adm/sulog | while read LINE
do
SUTMPUSR=$(echo $LINE | awk '{print $NF}')
SUTMPUSR=${SUTMPUSR%%-*}
SUUSR=$(grep $SUTMPUSR /etc/passwd | awk -F: '{print $5}')
echo "$LINE $SUUSR"
done >>${OUT}


And if you get tired of seeing the comma delimiters from
the name field, you can modify the SUUSR line like this to
get rid of them:

SUUSR=$(grep $SUTMPUSR /etc/passwd | awk -F: '{print $5}' | awk -F, '{print $1}')


JP
justin_83
Advisor

Re: awk question

Thanks John, that worked perfect.
N