I am trying to retrieve shell variables generated on the remote machine in an ssh session.
echo -n "Enter the raspberry ip address you want to connect:"
read Rasp_id
sshpass -pthe@Donut ssh -oStrictHostKeyChecking=no pi@"$Rasp_id" << 'E7'
#sudo rm -r SoundEye.zip
mac_add=$(ip link show wlan0 | grep link | awk '{print $2}')
timing=$(date)
E7
echo ${mac_add}
echo ${timing}
I have tried to pass variables from the ssh session (which are $mac_add
and $timing
) in this case, echo
it on the local machine. Putting /
in front of each variable doesn't help.
echo /${mac_add}
echo /${timing}
Same goes to adding export in front of each variable I want to declare. It doesn't solve the problem as well.
ip link ...
anddate
(i.e., don't capture the data in variables at all). – Kusalananda Jan 04 '21 at 08:16ssh <target> <command>
. So, e.g,ssh <target> 'echo ${mac_add}'
might work. Or write a script on the target (in your first coding, e.g.), call that as