From owner-freebsd-isp Fri Apr 10 17:21:43 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id RAA22495 for freebsd-isp-outgoing; Fri, 10 Apr 1998 17:21:43 -0700 (PDT) (envelope-from owner-freebsd-isp@FreeBSD.ORG) Received: from ymris.ddm.on.ca (p37a.neon.sentex.ca [207.245.212.230]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id RAA22481 for ; Fri, 10 Apr 1998 17:21:30 -0700 (PDT) (envelope-from dchapes@ddm.on.ca) Received: from squigy.ddm.on.ca (squigy.ddm.on.ca [209.47.139.138]) by ymris.ddm.on.ca (8.8.8/8.8.8) with ESMTP id UAA06897; Fri, 10 Apr 1998 20:21:22 -0400 (EDT) (envelope-from dchapes@ymris.ddm.on.ca) From: Dave Chapeskie Received: (from dchapes@localhost) by squigy.ddm.on.ca (8.8.8/8.8.7) id UAA11480; Fri, 10 Apr 1998 20:21:20 -0400 (EDT) Message-ID: <19980410202120.13093@ddm.on.ca> Date: Fri, 10 Apr 1998 20:21:20 -0400 To: Troy Settle Cc: freebsd-isp@FreeBSD.ORG Subject: Re: passwd to .htpasswd script Mail-Followup-To: Troy Settle , freebsd-isp@FreeBSD.ORG References: <006501bd6484$5c602f30$3a4318d0@abyss.b.nu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89i In-Reply-To: <006501bd6484$5c602f30$3a4318d0@abyss.b.nu>; from Troy Settle on Fri, Apr 10, 1998 at 09:27:07AM -0400 Sender: owner-freebsd-isp@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org 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