PDA

View Full Version : [BASH] Verifica IP in una lista


w0nz3r
05-09-2013, 12:13
Ciao a tutti!
Stavo scrivendo uno script che mi risolve un host e mi verifica nel file "lista" se è presente l'indirizzo IP
Al momento sono arrivato a questo punto:

#!/bin/bash

IP=`host pippo.com | grep address | awk '{print $4}'`
while read LIST_IP;
do
if [ "${IP}" != "${LIST_IP}" ]; then
echo "IP ADDRESS NON PRESENTE NELLA LISTA"
else
echo "IP ADDRESS PRESENTE NELLA LISTA"
fi
done < lista | grep -v "#"


Il problema è che io vorrei che se anche un solo IP presente nel file "lista" è presente, non deve restituirmi errore.

Mi sapreste dare la solita dritta?

Grazie come sempre!

-w-

Oceans11
07-09-2013, 18:18
inserisci un "break" alla fine del corpo dell'else (prima di "fi").

HexDEF6
23-09-2013, 18:22
qualcosa cosi' (non testato)

#!/bin/bash

IP=`host pippo.com | grep address | awk '{print $4}'`
while read LIST_IP;
do
if [ "${IP}" == "${LIST_IP}" ]; then
echo "IP ADDRESS PRESENTE NELLA LISTA"
exit
fi
done < lista | grep -v "#"
echo "IP ADDRESS NON PRESENTE"