When I run the following command it appears to work just fine.
$ pdsh -w root@skinner,root@mulder \
'export CRAWL_DATE=$(date +%Y%m%d); echo $CRAWL_DATE;'
Running as you're describing shows this:
$ pdsh -w root@skinner,root@mulder
pdsh> export CRAWL_DATE=$(date +%Y%m%d);
pdsh> echo $CRAWL_DATE;
Running it this way works though:
pdsh> export CRAWL_DATE=$(date +%Y%m%d); echo $CRAWL_DATE;
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 via
ssh on each host. The next command that is executed is run in an entirely different
ssh 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:
$ pdsh -w ^hostfile -Rexec ssh -2 -l %u %h '. ~/.pdsh/vars/%h; command'
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.