# cat list.txt
server1
server2
server3
server4
# data to be compared of.
#dns address
1.1.1.1
2.2.2.2
3.3.3.3
#for i in `cat list.txt`
do
grep dns $ i
done
Desired output:
#cat server1|grep dns
1.2.3.4
Then it will send an email that dns is different, not equal to 1.1.1.1 , 2.2.2.2 and 3.3.3.3
---------- Post updated at 10:52 PM ---------- Previous update was at 10:20 PM ----------
done,,we may clsed this
This is not clear and vague. At a guess you have a number of files, server1, server3, and server4.
File list.txt is a list of these files.
This part isn't clear, but it seems you have another file containing ip addresses, let's call this file valid_addresses.txt.
So file list.txt contains
server1
server3
server4
File valid_addresses.txt contains...
1.1.1.1
2.2.2.2
3.3.3.3
Let's say file server1 contains...
4.4.4.4
Let's say file server3 contains
3.3.3.3
Let's say file server4 contains
2.2.2.2
Then this script x.sh works...
#! /bin/ksh
for i in `cat list.txt`
do
ip=`cat ${i}`
if ! grep -q "${ip}" valid_addresses.txt
then
echo "DNS IP ${ip} from file ${i} not found in valid_addresses.txt"
fi
done
If you are using bash shell,
change top to !# /bin/bash
and if you want to email
change echo statement to something like...
echo "DNS IP ${ip} from file ${i} not found in valid_addresses.txt" | mailx -s "subject" someuser@host