I am using PDSH to control multiple servers through one command line.
The command below works fine on individual servers, but when I enter the export command within PDSH, echoing it back is empty.
Any ideas on why this is, or how to fix it?
Specific example:
This works just fine:
# export CRAWL_DATE=$(date +%Y%m%d);
# echo $CRAWL_DATE
20131206
but in PDSH, it echos blank values:
pdsh> export CRAWL_DATE=$(date +%Y%m%d);
pdsh> echo $CRAWL_DATE;
<IP 1>:
<IP 2>:
Best Answer
When I run the following command it appears to work just fine.
Running as you're describing shows this:
Running it this way works though:
So why didn't method #2 work?
The likely reason is that each time you run a command in
pdsh
and hit return that command is executed viassh
on each host. The next command that is executed is run in an entirely differentssh
session with a different shell, so the variable doesn't exist.This issue that was filed in 2011 I think gives credence to my conclusion. Issue 37: Support user defined variables in pdsh.
There was an interesting workaround mentioned in that issue, mainly:
This method makes use of a file that would contain the variables, and each command could then source this file,
. ~/.pdsh/vars/%h
each time a command is run remotely.