0

I am trying to access my local variable in remote server. Which command should I use.

Ex. cmd:

SERVER 1
VAR=2
ssh unix-user@remote-server-name "bash abc.sh"

REMOTE SERVER:

cat abc.sh
echo $VAR

output should get 2.

YesThatIsMyName
  • 1,585
  • 3
  • 23
  • 30
Patils
  • 65
  • 3
  • 10
  • 3
    Use ```man ssh``` and look for ```SendEnv```. – accdias Nov 21 '19 at 09:59
  • @accdias : I tried using SendEnv but not able to achieve it – Patils Nov 21 '19 at 10:08
  • 1
    @Patils If something is not working then you should post your command, and the error message. How do you expect someone to help you without more information. – YesThatIsMyName Nov 21 '19 at 10:21
  • @Patils, read the answer on my 2nd comment. You need to configure the remote server with ```AcceptEnv``` as well. – accdias Nov 21 '19 at 10:23
  • VAR=5 ; ssh -o SendEnv=VAR user@remote-hostname 'echo $VAR' ==> not getting any output @accdias any other command can you pls suggest here – Patils Nov 21 '19 at 12:47
  • In your example this might work: `source <(ssh unix-user@remote-server-name "cat abc.sh")` – Walter A Nov 21 '19 at 16:20

1 Answers1

0

Set the variable directly on the remote side:

ssh unix-user@remote-server-name "export VAR=2; bash abc.sh"
ceving
  • 21,900
  • 13
  • 104
  • 178