1826057 Members
4228 Online
109690 Solutions
New Discussion

user account info

 
SOLVED
Go to solution
Vic S. Kelan
Regular Advisor

user account info

Hi
I would really appreciate if someone can help me with a little scripting task I wanna do.

Basically I want to list the /etc/passwd, grep only the username for example only the "root" part of this "root:*:0:3::/:/sbin/sh". Pass each username through /usr/sbin/groups to identify and print user groups to a file. Then also pass each username through /usr/lbin/getprpw, and print out each users lockout=0000000 from the output of /usr/lbin/getprpw to same file so I can identify disabled accounts and for what reason based on the bit (1 or 0).

Thanks!!
3 REPLIES 3
Stuart Browne
Honored Contributor

Re: user account info

It's really quite simple to loop thorugh things like this. Here's an example shell script to do it:

OFS=$IFS
IFS=:
while read USR JUNK
do
echo $USR
done < /etc/passwd
IFS=$OFS

Inside the while loop there, you can do your 'groups' and 'getprpw' commands with $USR as the username.

If you want to use a different scripting language, then we can do that as well:

awk 'BEGIN {
OFS=FS
FS=":"
while ( getline <"/etc/passwd" ) {
print $1
}
FS=OFS
}'

Once again, within the while, you acn do what you need with $1 as the username.
One long-haired git at your service...
Ermin Borovac
Honored Contributor
Solution

Re: user account info

For deactivation task you may want to try the following script. It should print out all deactivated accounts including the reason for deactivation.

ftp://contrib:9unsupp8@hprc.external.hp.com/sysadmin/coolscripts/deactivated.sh
Vic S. Kelan
Regular Advisor

Re: user account info

Hi Ermin & Stuart,

Thanks for the help, both very useful and the script was great, Ermin!!