NPC
NPC

Reputation: 869

How do I pass variables between two servers?

I am taking input from user for a shell script, and want to run this script on different servers.

I tried to pass the variables as follows:

    USERNAME=****
    HOSTS="**** ***** *****"    
    FOO=$1
    BAR=$2
    for HOSTNAME in ${HOSTS} ; do
        ssh $USERNAME@$HOSTNAME bash << EOF

    #script using FOO and BAR variables goes here

    EOF

Login to the server is successful but variables are not being passed.

How can handle this situation without creating a temp file?

Upvotes: 1

Views: 341

Answers (2)

Bjoern Rennhak
Bjoern Rennhak

Reputation: 6966

Possible Duplicate of this SuperUser Answer.

In a nutshell: You can pass values with a command similar to the following:

ssh username@machine VAR=value cmd cmdargs

Upvotes: 1

nullByteMe
nullByteMe

Reputation: 6391

Do it like this:

VAR="something"

ssh $USERNAME@$HOSTNAME "

VAR=$VAR
export VAR

"

Upvotes: 1

Related Questions