Reputation: 1
I have the following sh script code that accesses my local router via SSH in order to find the real IP address of the router (vs. apparent IP created by my VPN).
The code works and I receive no errors but it doesn't return the string I would expect, ie. "External IP is 99.99.99.99
.".
If I execute each of the 3 commands separately within Terminal (ssh, getrealip.sh & echo) it works perfectly.
Anyone know what I am missing here?
Running the script on Mac OS accessing an Asus router. Script is to be run from a TextBar item.
#!/bin/sh
myip=$(ssh [email protected] 'myip=$(/usr/sbin/getrealip.sh); echo $myip')
echo "$myip"
exit
Should result in "External IP is 99.99.99.99
." string but actually returns null.
Upvotes: 0
Views: 124
Reputation: 109
I apologize for not have the most helpful answer, but from my experience, the '
literally interprets string values. So you'll get something like this:
bash-4.3# echo '$(hostname -I)'
$(hostname -I)
Try replacing '
characters with "
Also, be aware that subshells will be interpreted BEFORE the ssh call. so your PC will attempt to run the script before it connects to your router.
Maybe I'm not reading the question right, but you may not even need the subshell. IDK if the version of SSH uses the -t
option. but I'd recommend you change your SSH command to
myip=$(ssh [email protected] -t "sh /usr/sbin/getrealip.sh;")
Upvotes: 1