I am trying to create a bash function that will whitelist a IP on a remote VPS:
function whitelist-ip () { ssh vps-01 '/usr/bin/sudo /sbin/iptables -v -I INPUT 1 -s $1 -j ACCEPT'; }
[jdorfman@mba.local]:~$ whitelist-ip 192.0.43.10
Bad argument ‘ACCEPT’
Try iptables -h’ or ‘iptables –help’ for more information.’
It works in the CLI:
[jdorfman@mba.local]:~$ ssh vps-01 ‘/usr/bin/sudo /sbin/iptables -v -I INPUT 1 -s 192.0.43.10 -j ACCEPT’
ACCEPT all opt — in * out * 192.0.43.10 -> 0.0.0.0/0
You hardquoted the command, so
$1does not expand. Use soft quotes instead: