Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

who's using Bourne?

Status
Not open for further replies.

Tuttle01

MIS
Oct 22, 2001
1
US
Howdy!

I'm trying to write a Korn shell script to get a count of all users who, by default, are using /bin/sh. I'm getting this info via the etc/passwd file so if the last field of this file is blank then it's assumed they are also using /bin/sh.

It's a simple one line script (awk not needed) but I'm having a Blonde moment.

TIA!

Tuttle01
 
This will tell you the number of your /bin/sh users:

cat /etc/passwd | grep '/bin/sh' | wc -l

Will have a further think about the blank defaults. HTH.
 
Thinking in reverse (nothing new there then!), you could exclude any other shells using something like:

cat /etc/passwd | grep -v /bin/ksh | grep -v '/usr/bin/ksh'| grep -v....etc | wc -l

By the way, what's a 'Blonde', and do they have more fun?
 
Why call 'wc' when 'grep' can count the matches for you? The '-c' option gives a count of the matches. The other advantage is that 'grep -c' doesn't add those annoying leading spaces like 'wc -l'.

cat /etc/passwd | grep -c '/bin/sh'
 
Good point. However, I still think my second suggestion of reverse engineering the thing will work better for Tuttle01's requirement to include those entries without a shell (and therefore by default bourne shell users). Cheers.
 
Code:
cat /etc/passwd | awk '/:$/ {print $0} /\/sh$/ {print $0}'

or with nis (could be used for passwd too) ... (i like awk ...)
Code:
niscat passwd.org_dir | awk '{squ=split($0,sp,":"); if (squ >=14 && (length(sp[7]) == 0 || index(sp[7],"/sh") > 0)) {print sp[1];}}'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top