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.

1
  • perhaps scriptb needs varA=$1 ?
    – Jeff Schaller
    Sep 6, 2017 at 13:22

1 Answer 1

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
3
  • also tried that. did not work
    – oakley00
    Sep 6, 2017 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, 2017 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. Sep 6, 2017 at 11:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .