plz help with this script,
I wish to ssh this command to several hosts:
ls -alst "dir with spaces"
This script is close but I need DOUBLE-quotes around the remote commands
#! /bin/bash
PARAMS_FOR_LS=(-alst "dir with spaces")
# get directory of local system
ls "address@hidden"
# get directory of remote systems
#do search 'x' for a hostname; get host1
ssh host1 ls "address@hidden"
#do search 'y' for a hostname; get host2
ssh host2 ls "address@hidden"
#do search 'z' for a hostname; get host3
ssh host3 ls "address@hidden"
I have tried several variations of eval and echo.
plz help
Greg,
your Cc did not contain my question.
I was not able to use your answer.
I get the following:
+ ssh ccn000 bash 'ls "address@hidden"' EOF
/bin/ls: /bin/ls: cannot execute binary file
From: "Greg Wooledge" <address@hidden>
To: address@hidden
Cc: address@hidden, address@hidden
Sent: Wednesday, July 17, 2013 2:52:11 PM
Subject: Re: script with ssh and filenames with spaces
On Wed, Jul 17, 2013 at 08:42:17PM +0000, address@hidden wrote:
> I wish to ssh this command to several hosts:
> ls -alst "dir_with_spaces"
for host in "address@hidden"; do
ssh "$host" bash <<-'EOF'
ls -alst "your directory"
EOF
done
The - in front of the here document's delimiter allows indentation with
tabs only (not spaces).
I Cc'ed address@hidden because that's more appropriate for this
question.