From owner-freebsd-questions@FreeBSD.ORG Fri Aug 1 06:25:03 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 23E3E37B401 for ; Fri, 1 Aug 2003 06:25:03 -0700 (PDT) Received: from mail.sacbee.com (filter.sacbee.com [206.107.198.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5C3CF43FE0 for ; Fri, 1 Aug 2003 06:25:02 -0700 (PDT) (envelope-from scoile@nandomedia.com) Received: by EXCHANGEMCC with Internet Mail Service (5.5.2653.19) id ; Fri, 1 Aug 2003 06:26:20 -0700 Received: from [10.1.1.45] (10.1.1.45 [10.1.1.45]) by exchangemcc.mcclatchy.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id P88YNWLV; Fri, 1 Aug 2003 06:26:17 -0700 From: Steve Coile To: "Dave [Hawk-Systems]" Date: Fri, 1 Aug 2003 09:20:15 -0400 (EDT) X-X-Sender: scoile@localhost.localdomain In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: FreeBSD Questions Subject: RE: 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 13:25:03 -0000 Dave: >From your description of the script, and from the script itself, it appears that the reason you're checking for a blank command is to determine when you've reached the end of commands. Presumably, that would only occur at the end of the file. Is my interpretation correct? If the reason you're looking for that blank line is to find the end of commands, you could approach the problem this way: - move the original file containing commands into a temporary file; - create an empty file in the original location; - execute the commands from the temporary file; - delete the temporary file. In this way, you avoid having the file of commands updated while you're reading through it and executing commands. You also avoid a number of potential programatic pitfalls that are present with your current approach, pitfalls that may result in the loss of changes to the file containing commands. So: #/bin/sh CMDFILE=/path/to/file_o_commands # move current file to temporary location mv -f "${CMDFILE}" "${CMDFILE}.tmp" # create an empty command file touch "${CMDFILE}" # commands are coming from the temporary file eval < "${CMDFILE}.tmp" # read each command while read command do # execute each command via SSH eval ssh ${command} done # delete the temporary file rm -f "${CMDFILE}.tmp" Note the use of "eval". It's necessary because the example you included in your original posting included commands that include shell special characters, such as the pipe ("|"). Without the "eval" command, those characters would not be treated the way you appear to want them treated (as special characters). -- Steve Coile Systems Administrator Nando Media ph: 919-861-1200 fax: 919-861-1300 e-mail: sysadmins@nandomedia.com http://www.nandomedia.com