Operating System - HP-UX
1826414 Members
4142 Online
109692 Solutions
New Discussion

passwd script frustration

 
SOLVED
Go to solution
Stephanie L Davenport
Frequent Advisor

passwd script frustration

Ok, I'm trying to get information about disabled users on my system. I wrote a simple for loop but, it is not working the way I want it to.

#> for a in `cat listOfUsers `;do
>grep $a /etc/passwd | awk -F: '{print $1 ":" $6}' >> Info.txt
>done


But, all I get is the information on the last person in the list. What am I doing wrong?
3 REPLIES 3
Dennis Handly
Acclaimed Contributor
Solution

Re: passwd script frustration

Without trying this, it seems fine. What is the format for listOfUsers?

If there is one name per line, you could use:
grep -f listOfUsers /etc/passwd | awk -F: '{print $1 ":" $6}' >> Info.txt
James R. Ferguson
Acclaimed Contributor

Re: passwd script frustration

Hi Stephanie:

What does your file, 'ListOfUsers' look like? If it has one user (name) per line, this should work.

That said, you can eliminate *two* extra processes! --- a 'cat' and a 'grep'. Let the shell read and split the fields. Let 'awk' match what you need and print it.

#/usr/sin/sh
while read NAME X; do
awk -v NAME=${NAME} -F: '$1==NAME {print $1 ":" $6}' /etc/passwd
done < listOfUsers > info.txt
exit 0

Regards!

...JRF...
Stephanie L Davenport
Frequent Advisor

Re: passwd script frustration

Both are wonderful suggestions. But, my problem was that I ftp'd the file over from windows and it had the ^M at the end of every line. :) I hadn't noticed because I was using "more" instead of "vi" on the file.

It's always those little things that get you.

Thanks for your help!