Passing variables via ssh

I am trying to write a script to login to several remote servers and execute a script on each server. However, I would like to pass the variable through ssh. Something like that:

var="/home/dir/"

  ssh -T $mchname <<'ENDSSH'    
    $var"run_script" < input > output &    
ENDSSH

This naive attempt does not work ($ var is just null). What would be the correct syntax? Thanks in advance.

+5
source share
2 answers

Remove the quotation marks from the page ENDSSH. They prevent the expansion of variables in this document .

+4
source

Try the following:

var="/home/dir/"

  ssh -T $mchname VAR=$var 'bash -s'<<'ENDSSH'    
    $VAR"run_script" < input > output &    
ENDSSH
+2
source

All Articles