I would like to set Linux environment variables in net-ssh start and use them further down in my code. But I am losing the scope of the variables. Can you please advise how that can be achieved.
I am using net-ssh and logging into Linux via rsa key. I have set a environment variable which I would like to use further down but I am losing the scope of the variable.
ssh = Net::SSH.start(host,
username
)
result = ssh.exec!('setenv SYBASE /opt/sybase && printenv') ### Can See environment variable SYBASE
puts result
puts "**********************************************************************************"
result = ssh.exec!('printenv') #### Lost the environment variable SYBASE set above
puts result
puts "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
Each exec creates an environment on it's own, environmont variables are lost. Like you do with your
&&(execute next command if first succeeds) or with;(execute anyway) you can chain commands.You can also send a block like this to do multiple actions
Or use the gem net-ssh-session.