Click to See Complete Forum and Search --> : This should be easy


AstroDroid
05-25-2004, 03:34 PM
I have a shell script that invoices the following command

nbtscan -s : -v 192.168.6.30-254 | grep -e "computername" -i | awk -F: '{print $1}'

The problem is that nbtscan returns the name 3 times. So I get the following output

192.168.6.68
192.168.6.68
192.168.6.68

I need only the first IP.

I use this to launch vnc to the machine, and in it's current state it runs

vncviewer 192.168.6.68 192.168.6.68 192.168.6.68

of course this doesn't work, thoughts?

This makes it easy to run vnc without knowing the IP, so I just type

prog office username

and it finds the ip and logs me in. with no user intervention.

PS -- Bash only please, I know you could do this with perl, but I choose bash. Thanks.

jim mcnamara
05-25-2004, 03:44 PM
Did you try uniq


nbtscan -s : -v 192.168.6.30-254 | grep -e "computername" -i | \
sort | uniq -d | awk -F: '{print $1}'



Or something along those lines

Ludootje
05-25-2004, 04:14 PM
Yes uniq would work I think, otherwise 'head -n 1' or 'tail -n 1', depends if it always give the same output 3 times, or if the IP's are different sometimes.

AstroDroid
05-25-2004, 04:36 PM
Thanks!! it worked (both of them)