[Gllug] Help with Script.

Andy Millar andy at andymillar.co.uk
Mon Jan 10 15:40:21 UTC 2011


On Mon, 2011-01-10 at 15:24 +0000, Martin N Stevens wrote:
> #!/bin/bash
> 
> nmap 10.72.92.0/22 -sP | grep MAC | cut -d " " -f3 > live.txt
> 
> cat live.txt | while read line; do
>         grep $(line) mac.txt > /dev/null 2>&1
>         if [ $? -eq 1 ]; then
>                 echo "Mac not known $(line). Adding to mac.txt file"
>                 echo $(line) >> mac.txt
>         fi
> done
> 
> rm live.txt

This should work:

nmap 10.72.92.0/22 -sP | grep MAC | cut -d " " -f3 > live.txt
 
cat live.txt | while read line; do
        if [ -z "$(grep $line mac.txt 2>&1)" ]; then
                echo "Mac not known $(line). Adding to mac.txt file"
                echo $(line) >> mac.txt
        fi
done

rm live.txt


Or you could do:

nmap 10.72.92.0/22 -sP | grep MAC | cut -d " " -f3 > live.txt
(cat live.txt ; cat mac.txt) | sort -u > /tmp/.mac.txt.$$
rm -f mac.txt
mv .mac.txt.$$ mac.txt
rm -f live.txt

Which seems to be a little less evil. If you care about the new lines,
you can always use diff.

Andy


-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list