It is common to keep track of IP address in a worksheet.
I just tried it out. In the first column was a numer that could be a room number.
The second column was the IP address. I used a user defined format code of "192.168.1."@
and then entered the last octet into each field. If they are consecutive you could fill it with a series.
Then I saved it as a csv file. I didn't use a text delimiter.
Code:
roomiptable.csv
cat iproomtable.csv
123,192.168.1.100
214,192.168.1.101
111,192.168.1.102
112,192.168.1.102
113,192.168.1.104
114,192.168.1.105
115,192.168.1.106
116,192.168.1.107
118,192.168.1.108
119,192.168.1.109
120,192.168.1.110
121,192.168.1.111
Now you can read this table into an array variable in bash.
Code:
# Read in the table
> iptable=($(cat iproomtable.csv ))
# Display the first entry
> echo ${iptable[0]}
123,192.168.1.100
# Display the IP address of the first entry
> echo ${iptable[0]#*,}
192.168.1.100
# Display the Room number of the second entry
> echo ${iptable[1]%,*}
214
Since you have 300 IPs, it would be easier to use a loop.
Code:
# clear out the old logfile
:> logfile
# MAX = number of entries
MAX=${#iptable[@]}
# Ping each IP address in table and log failures
for (( index=0; index<MAX; index++ )); do
$5_sec_ping ${iptable[$index]#*,} || echo "Room ${iptable[$index]%,*} ${iptable[$index]#*,} is down" >> logfile
This will ping each of the ip address in the csv file and only log failures to the logfile with a line containing the room number and the IP address.
You could instead read the csv file one line at a time in a while loop instead of using an array variable.