I am trying to compare two strings. One value is coming from iptables
and the other is from a file where I saved previous records.
I want to identify if there is a new user appear in iptables. If so I will add that record to my file.
Here what I have tried so far.
chain=$(/usr/sbin/iptables -vnL | grep "references" | awk '{print $2}')
file=/data/..../2011-11.txt
for i in $chain
do
while IFS=',' read -r f1 f2 f3 f4 f5
do
user=$f1
if [ $i == "$user" ]; then
echo "user matched $user"
elif [ $i != $user ]; then #a new user
echo "new user $i"
break
fi #user matching if
done < "$file"
done #reading data from the file for loop
My iptables looks like (chain)
NalindaChainksSdt
KasunikaChainyCehf
KivinduChainmzWeN
KumudikaChainsXcAp
LocalServerChainRyqvv
File values are (file)
NalindaChainksSdt
KasunikaChainyCehf
Here script should ignore NalindaChainksSdt
and KasunikaChainyCehf
names from chains. (user matched)
But this does not do the trick. It just identify all users in the file as new users.
What am I missing here?