Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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>:
share|improve this question
2  
You need to show exactly what you are executing. –  jordanm Dec 7 '13 at 2:54

1 Answer 1

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;'
skinner: 20131206
mulder: 20131206

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;
skinner: 
mulder: 

Running it this way works though:

pdsh> export CRAWL_DATE=$(date +%Y%m%d); echo $CRAWL_DATE;
skinner: 20131206
mulder: 20131206

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.

share|improve this answer
    
My guess would be that in method 2, it's running each command in a different shell. –  jordanm Dec 7 '13 at 3:12
    
@jordanm - mine too. I'm looking into the setting of variables using pdsh now. That seems to be where the smoke is coming from. –  slm Dec 7 '13 at 3:15
    
@jordanm - there is this feature request which makes me believe that the exporting of variables isn't supported, because each command is run as a ssh each time you hit return. –  slm Dec 7 '13 at 3:17
    
exported environment variables are not persisted between sessions. In method2, each command is batched out in a fresh ssh session. –  ryanj Dec 7 '13 at 3:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.