Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing variables through ssh

Tags:

bash

ssh

I am trying to write a script to login to several remote servers and execute a script in each server. However, I'd like to pass a variable through ssh. Something like this:

var="/home/dir/"

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

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

like image 279
user1477337 Avatar asked Jun 30 '12 21:06

user1477337


1 Answers

Remove the quotes from around ENDSSH. They prevent expansion of variables within the here document.

like image 126
Dennis Williamson Avatar answered Dec 19 '22 11:12

Dennis Williamson