From owner-freebsd-questions@FreeBSD.ORG Thu Jul 31 18:12:47 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4828037B401 for ; Thu, 31 Jul 2003 18:12:47 -0700 (PDT) Received: from web1.nexusinternetsolutions.net (web1.nexusinternetsolutions.net [206.47.131.12]) by mx1.FreeBSD.org (Postfix) with SMTP id 59D4243FBF for ; Thu, 31 Jul 2003 18:12:46 -0700 (PDT) (envelope-from dave@hawk-systems.com) Received: (qmail 9949 invoked from network); 1 Aug 2003 01:12:42 -0000 Received: from unknown (HELO ws1) (65.49.236.97) by web1.nexusinternetsolutions.net with SMTP; 1 Aug 2003 01:12:42 -0000 From: "Dave [Hawk-Systems]" To: "FreeBSD Questions" Date: Thu, 31 Jul 2003 21:12:41 -0400 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal Subject: shell scripting while if string length != 0 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Aug 2003 01:12:47 -0000 for reasons best left unsaid, we need to pull in a file full of partial commands, and run them via a shell script on occasion, removing each command as we run it. Have managed to hack togetherthe following shell script, but and stumped on something simple because of my lack of shell knowledge; the file that holds out commands Server1 df -k Server2 df -k Server3 top | grep myprog Server4 who add new commands to the end of the file with echo "Server2 who" >> /path/to/file_o_commands then when we need to, run through the commands #!/bin/sh # get top command DOCOMMAND=`head -n 1 /path/to/file_o_commands` # remove that command cat /path/to/file_o_commands | sed '1d' > /path/to/file_o_commands # run that command ssh ${DOCOMMAND} this works as intended with 1 exception, we need to add a while in there to loop through the file and stop processing an exit when `head -n 1 /path/to/file_o_commands` does not return a line. I almost want to borrow -n from if while [ -n (DOCOMMAND=`head -n 1 /path/to/file_o_commands`) ] do ...rest of script... done Anyone care to enlighten me a bit? Dave