From owner-freebsd-questions@FreeBSD.ORG Mon Jul 25 10:09:18 2005 Return-Path: X-Original-To: questions@freebsd.org 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 9756116A420 for ; Mon, 25 Jul 2005 10:09:18 +0000 (GMT) (envelope-from dgerow@afflictions.org) Received: from pandora.afflictions.org (asylum.afflictions.org [64.7.134.90]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0782543D53 for ; Mon, 25 Jul 2005 10:09:17 +0000 (GMT) (envelope-from dgerow@afflictions.org) Received: from localhost (localhost [127.0.0.1]) by pandora.afflictions.org (Postfix) with ESMTP id 7C42278C78; Mon, 25 Jul 2005 06:12:29 -0400 (EDT) Received: from pandora.afflictions.org ([127.0.0.1]) by localhost (pandora.afflictions.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 78689-10; Mon, 25 Jul 2005 06:12:19 -0400 (EDT) Received: from dementia.afflictions.org (dementia.afflictions.org [172.19.206.56]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pandora.afflictions.org (Postfix) with ESMTP id 8F8E978C6D; Mon, 25 Jul 2005 06:12:17 -0400 (EDT) Received: by dementia.afflictions.org (Postfix, from userid 1001) id 91E5233C64; Mon, 25 Jul 2005 06:09:02 -0400 (EDT) Date: Mon, 25 Jul 2005 06:09:02 -0400 From: Damian Gerow To: "Gary W. Swearingen" Message-ID: <20050725100902.GI2461@afflictions.org> References: <20050725003238.GD2461@afflictions.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-GPG-Fingerprint: B3D7 D901 A53A 1A99 BFD6 E6DF 9F3B 742B C288 9CC9 User-Agent: Mutt/1.5.9i X-Virus-Scanned: amavisd-new at pandora.afflictions.org Cc: questions@freebsd.org Subject: Re: Shell scripts, SSH sessions, and for loops, oh my! X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jul 2005 10:09:18 -0000 Thus spake Gary W. Swearingen (garys@opusnet.com) [25/07/05 02:13]: : > I'm trying to write a shell script that runs a for loop in an SSH session. : > Simply, I'm trying to do this: : > : > for HOST in `cat hostnames` ; do : > ssh ${HOST} "for PROCESS in 01 02 ; do echo '${PROCESS}' ; done" : > done : > : > But because this is run in a script, that gets translated to: : > : > for HOST in `cat hostnames` ; do : > ssh ${HOST} "for PROCESS in 01 02 ; do echo '' ; done" : > done : : Here's a few clues (assuming you really want the single quotes in there): : : echo "THIS is SHELL: '\$SHELL'" : echo "THIS is SHELL: '"'$SHELL'"'" : echo 'THIS is SHELL: '\''$SHELL'\' : : which all give : : THIS is SHELL: '$SHELL' Yeah, but... The current shell still interprets $SHELL, and assigns it whatever local value it has. I don't want that. I want $SHELL to be evaluated by the remote system (the on to which I am establishing the SSH connection). To answer my own question: it looks like sh just isn't the right tool for the job. I'm going to have to either completely change my approach to the problem I'm trying to solve, or use Perl and Net::SSH (and given my problem, I'm tending towards the latter). - Damian