I read the other postings on passing variables in remote ssh, but those solutions don't seem to work for me.
Here is my situation: I'm populating the values of my variables throughout my shell script (on a local machine), which are then used on another system via ssh. I understand why this isn't working, but I'd like to find a way to use values in a local shell on another system via ssh.
BUILD_SERVER="my_server"
ANOTHER_SERVER="my_server2"
ssh $USERNAME@$BUILD_SERVER << 'ENDSSH'
echo "$BUILD_SERVER"
echo "$ANOTHER_SERVER"
ENDSSH
When I run this code, these variables are null. Is there any way to pass through the values to ssh?
I figured it out. On the line where I was doing the following:
ssh $USERNAME@$BUILD_SERVER << 'ENDSSH'
I removed the single quotes and it now interprets allow of my local variables. If I want to use a variable on the remote server I just escape them with a "\"
ssh $USERNAME@$BUILD_SERVER << ENDSSH
echo $BUILD_SERVER # echos the local server variable
LOCAL_SERVER="local_server"
echo \$LOCAL_SERVER # echos the remote server variable
ENDSSH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With