From owner-freebsd-questions Thu Jul 19 18:40: 3 2001 Delivered-To: freebsd-questions@freebsd.org Received: from guru.mired.org (okc-27-141-144.mmcable.com [24.27.141.144]) by hub.freebsd.org (Postfix) with SMTP id 577AE37B405 for ; Thu, 19 Jul 2001 18:39:57 -0700 (PDT) (envelope-from mwm@mired.org) Received: (qmail 56275 invoked by uid 100); 20 Jul 2001 01:39:56 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15191.35820.325672.101326@guru.mired.org> Date: Thu, 19 Jul 2001 20:39:56 -0500 To: Alex Dyas , Olivier Cortes Cc: questions@freebsd.org Subject: RE: Shell scripting gurus I nedd your help In-Reply-To: <55717934@toto.iv> X-Mailer: VM 6.90 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Alex Dyas types: > $ for address in `cat admins.txt`;do ls -al | mail -s "Ouput of ls command" > $address;done You're running the ls once per address. This may not give the desired results, and certainly uses more CPU than generating the list once. Olivier Cortes types: > ----------------------------------- > #!/bin/blash > > COMMAND='ls -la' > MSGFILE="my_temp_fic_1012380293476234" > ADDRFILE="admins.txt" > > $COMMAND > $MSGFILE 2>&1 > > while read ADDR > do > mail -s "$COMMAND" $ADDR < $MSGFILE > done < $ADDRFILE Both of these work, but have the same basic problem - they create a mail process for every address, which uses a lot of resources. It also creates a message - with a different message id - for every user, which can screw up message threading. It also means you have to wait for the mail to be delivered before starting the next command, which can add up to quite a bit of real time. You could background the mail commands, but that risks running out of processes, or spool space, or some other resource. If you hand the message and addresses to the MTA properly, you should only have to wait for one message to be delivered. The MTA will then give it a messageid, and deliver it as efficiently as possible. In the extreme case, the MTA might deliver one message along with the destination addresses to a remote server, which would just keep one copy of the message along with pointers in each readers mailbox, meaning you've just multiplied cpu, network and disk usage by the number of addresses. Since the mail command can handle multiple addresses, sending the message to `cat admins.txt` is one way of handing things off to the MTA. Going with an alias gives the MTA an even better chance to lower usage, and makes the list available for other uses as well. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message