Date: Fri, 10 Apr 1998 20:21:20 -0400 From: Dave Chapeskie <dchapes@ddm.on.ca> To: Troy Settle <rewt@i-Plus.net> Cc: freebsd-isp@FreeBSD.ORG Subject: Re: passwd to .htpasswd script Message-ID: <19980410202120.13093@ddm.on.ca> In-Reply-To: <006501bd6484$5c602f30$3a4318d0@abyss.b.nu>; from Troy Settle on Fri, Apr 10, 1998 at 09:27:07AM -0400 References: <006501bd6484$5c602f30$3a4318d0@abyss.b.nu>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Apr 10, 1998 at 09:27:07AM -0400, Troy Settle wrote: > #!/bin/sh > count=`/usr/bin/wc -l /etc/master.passwd | awk '{ print $1}'` > numusers=`/bin/expr ${count} - 14` > /usr/bin/tail -n ${numusers} /etc/master.passwd | /usr/bin/cut -f 1,2 -d : This is VERY inefficient. It involves two passes over the file one of which needs to buffer almost the whole file! Also it makes assumptions about the number of system accounts, if you add a new system account (majordomo, postgres, etc) you have to find and change your script. A MUCH better solution would be: awk -F: '$3 >= 1000 {print $1 ":" $2}' /etc/master.passwd One command, one pass, one assumption. You replace 1000 with the starting UID of real users (as opposed to system accounts). Any smart sysadmin keeps all system account UIDs bellow a certain value so this is not as bad of an assumption. (BTW, if you want this one command as a script use something like: #!/bin/sh exec awk -F: '$3 >= 1000 {print $1 ":" $2}' /etc/master.passwd I dislike it when people forget the exec.) Please refrain from posting scripts or answers to the mailing lists unless you know what you are doing. (Not to single you out, but I've seen a lot of very poor or wrong answers posted to lists and it annoys me sometimes). IMHO bad answers/examples are worse than no answers/examples. -- Dave Chapeskie, DDM Consulting E-Mail: dchapes@ddm.on.ca To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-isp" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980410202120.13093>