Help: Bash Script
Hello all, i am new to bash scripting and have spent hours trying to figure out why the following script will not work.
for host in 192.168.1.{100..109}; do ping -c 1 -t 1 $host > /dev/null 2> /dev/null if [ $? -eq 0 ]; echo $host fi done > hostup.txt The script works fine when run on my own computer. However i am trying to apply the same script at work where the ip address range is different, e.g. (192.168.1.{1..55}) upon running this script remotely from my system., i get the error 'ping unknown host 192.168.1.{1..55}. Any help on this matter would be greatly appreciated! Thanks |
"==However i am trying to apply the same script at work where the ip address range is different, e.g. (192.168.1.{1..55}) upon running this script remotely from my system., i get the error 'ping unknown host 192.168.1.{100.109}. Any help on this matter would be greatly appreciated!=="
Did you change the 'for' line into effective ip block in that given subnet? Does the given network has an effective dns? 192.168.xxx.xxx is an intranet class ip. If you ping an address beyond what the subnet block assigned it cannot resolve unless the router provides an effective dns to resolve the query. Hope it helps. |
Quote:
EG:- Code:
for IP in 192.168.1.{100.109} Code:
for IP in 192.168.1.{100..109} |
thanks for the replies! Basically when i remotely login into the system and carry out the same command in a terminal, it works with no problems, e.g. I get a text file called hostup.txt with the IP addresses that are up.
However if i save the commands in a script (test.sh). When i run it i get the ping error. |
The following code works as intended:
Code:
#!/bin/bash Please compare your code with the version you have posted. If your code was written the way you posted it, you would not get an error message, as they would be directed to /dev/null If you run: Code:
ping -c 1 -t 1 192.168.1.{1.55} > /dev/null ping unknown host 192.168.1.{1.55} If you run: Code:
ping -c 1 -t 1 192.168.1.{1..55} > /dev/null If you run: Code:
ping -c 1 -t 1 192.168.1.{1.55} > /dev/null 2>/dev/null |
All times are GMT -5. The time now is 10:30 PM. |