I saved ports in an array that I wanted to check, then I'm running a for loop to check for the port in iptables rule list. I want to echo Ports that are not in the iptables list with msg not found. Tried to add an if condition inside the loop but not working. here's the code: [Non-working ;) ]
#!/bin/bash
array=( 3306 1403 8080 443 22 )
for i in "${array[@]}"
pc=(iptables --list | grep $i | cut -d " " -f1)
do
if [ "${pc}" = "ACCEPT" ]
then
echo "ok"
else
echo "Port not found"
fi
done
Error:
array.sh: line 4: syntax error near unexpected token `|'
array.sh: line 4: `pc=(iptables --list | grep $i | cut -d " " -f1)'
array.sh: line 5: syntax error near unexpected token `do'
array.sh: line 5: `do'