set a parameter by export in remote machine

53 views
Skip to first unread message

Sundi

unread,
Feb 20, 2013, 11:24:05 PM2/20/13
to parallel-ssh
Hi I am trying to set a param in remote machines specified by the
cluster.
pssh -h nodes -l $USER -P "export TODAY=$(date +"%F");export
NODE_NAME=`hostname` ; cp /home/\$NODE_NAME/grid /home/hadoop/grid",
But NODE_NAME always returns localhost. When I run hostname in the
remote machines i get the proper hostnames as hostname1 or hostname2.
What might be the issue. Thanks
Sundi

Andrew McNabb

unread,
Feb 21, 2013, 12:53:05 PM2/21/13
to parall...@googlegroups.com
Dealing with environment variables with ssh can be delicate. The
problem is that the substitutions are happening on your machine instead
of on the remote machine. In the specific case you gave, using double
quotes instead of single quotes will tell your shell to send the string
without performing substitution:

pssh -h nodes -l $USER -P 'export TODAY=$(date +"%F");export NODE_NAME=`hostname` ; cp /home/$NODE_NAME/grid /home/hadoop/grid'

In some other cases, getting everything to work can be even more
complex, but this should work for your situation.

--
Andrew McNabb
http://www.mcnabbs.org/andrew/
PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868

Sundi

unread,
Feb 21, 2013, 8:52:07 PM2/21/13
to parallel-ssh
Stilll not working,
pssh -h nodes -l $USER -P "export NODE_NAME=`hostname` ; mkdir
$NODE_NAME"
error
mkdir: missing operand

if I try with \$NODE_NAME, localhost directory gets created but I dont
want that.
Only solution seems to use a script and pass it along params to
it.overhead is to maintain that script in a separate file.

Have you tried the "" in remote machines ?

Thanks
Sundi
> Andrew McNabbhttp://www.mcnabbs.org/andrew/

Andrew McNabb

unread,
Feb 22, 2013, 1:07:36 PM2/22/13
to parall...@googlegroups.com
On Thu, Feb 21, 2013 at 05:52:07PM -0800, Sundi wrote:
> Stilll not working,
> pssh -h nodes -l $USER -P "export NODE_NAME=`hostname` ; mkdir
> $NODE_NAME"
> error
> mkdir: missing operand

Yeah, you're still using double quotes here. You really need single
quotes (my explanation is in the previous message).


--
Andrew McNabb

Sundi

unread,
Feb 23, 2013, 12:58:19 PM2/23/13
to parallel-ssh
works charm thanks :)

On Feb 22, 10:07 am, Andrew McNabb <amcn...@mcnabbs.org> wrote:
> On Thu, Feb 21, 2013 at 05:52:07PM -0800, Sundi wrote:
> > Stilll not working,
> > pssh -h nodes -l $USER -P "export NODE_NAME=`hostname` ; mkdir
> > $NODE_NAME"
> > error
> > mkdir: missing operand
>
> Yeah, you're still using double quotes here.  You really need single
> quotes (my explanation is in the previous message).
>
> --
> Andrew McNabbhttp://www.mcnabbs.org/andrew/
Reply all
Reply to author
Forward
0 new messages