I am trying to remove UFW rules through SSH using the following bash script:
#!/bin/bash
ip=$(dig @resolver4.opendns.com myip.opendns.com +short)
sshpass -p 'password' ssh -tt -p 22 root@192.168.1.20 ufw show added | awk -v ipm="$ip" '$0 ~ ipm{ gsub("ufw","ufw delete",$0); system($0)}'
It connects successfully on the remote host but somehow the command
ufw show added | awk -v ipm="$ip" '$0 ~ ipm{ gsub("ufw","ufw delete",$0); system($0)}'
is not executed correctly because I receive the following error:
Connection to 192.168.1.20 closed. 'RROR: Bad port '3306
The IP is whitelisted only for port 3306.
I assume it gives this error because I use sshpass utility On the host it works perfectly. Somehow the UFW rule to remove the IP is not interpreted correctly through ssh. I don’t know how to debug this. Thanks!