1

I have a script that will ssh to another server.

Script A will get the value of $variableA, then will ssh to another server to execute a script B which will need the value of $variableA.

I tried below but script B is not recognizing the value of $variableA

scriptA"

varA=`hostname`
ssh -x serverB "/home/dir/scriptb.sh $varA"

Script B from 2nd server:

echo $varA

ScriptB from 2nd server won't echo $varA.

0

Your script scriptb.sh on remote server got that variable by value as the 1st positioned argument.
To output the 1st argument passed to shell script:

echo $1
  • also tried that. did not work – oakley00 Sep 6 '17 at 11:26
  • @oakley00 You should use $1 in the script that executes remotely (instead of $varA). That ought to work. If not, update the text in the question with information about what "doesn't work". – Kusalananda Sep 6 '17 at 11:27
  • 1
    Note that the content of $varA will be passed as the first argument to scriptb.sh only if it contains none of the special characters of the login shell of the user on the remote host. For instance, if $varA contained $(reboot) (quite unusual for a hostname) and the login shell of the user was POSIX-like, that would cause reboot to be called instead. – Stéphane Chazelas Sep 6 '17 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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