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
    CommentedSep 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
    CommentedSep 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
    CommentedSep 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.CommentedSep 6, 2017 at 11:48

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.