[Gllug] Help with Script.

Stuart Sears stuart at sjsears.com
Mon Jan 10 17:59:59 UTC 2011


On 10/01/11 15:24, Martin N Stevens wrote:
> Hi,
> 
> I am trying to write a script that will collect all the mac addresses
> on my network, it will be run periodically to update a file called
> mac.txt
> 
> However the matching part doesn't seem to be working. Any clues please.
> 
> ================================
> 
> #!/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

Are those parentheses - () or braces {} throughout that script?

$(line) is trying to run a command called 'line' and then grep for the
output in mac.txt. Which is unlikely to work.

${line} or just $line will substitute the variable 'line' into that
command, which seems to be what you want

>         if [ $? -eq 1 ]; then
>                 echo "Mac not known $(line). Adding to mac.txt file"
>                 echo $(line) >> mac.txt
>         fi
> done
> 
> rm live.txt

I'd have done this instead...
nmap -sP NET | awk '/^MAC/ {print $3}' | while read line; do...

but then that's just me.

Stuart
-- 
Stuart Sears RHCA etc.
"It's today!" said Piglet.
"My favourite day," said Pooh.
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list