Quote:
Originally Posted by bogidu
I'm wanting to create a command line script that runs ping against each line of the /etc/hosts file.
I think I've got the basics of it but don't have something quite right.
$ for each $i in /etc/hosts
> do
> ping $i
> done
Yes, I know my syntax is wrong, I'm just trying to figure out where I'm screwing this thing up. Any help is appreciated, Thanks.
Bill
|
for i in $(cat /etc/hosts)
should work for reading the hosts file, but then you will need to use cut/grep/sed to get rid of the excess information (i.e. comments, hostnames and so on). I think you'll also need to set IFS like this before the for-loop:
IFS=$'\x0A'$'\x0D'
Remember to unset it after the loop.