Hi
I have webserver that I do read data from.
Data are stored like this:
Huston |1
Portland |2
Hazen |1
Minneapolis |4
Albany |1
Pittsburg |1
Albany |1
Huston |1
Portland|1
Hazen |2
Albany |2
Huston |1
Hazen |1
Script
#!/bin/sh
user="admin"
pass"demo"
server="192.168.1.10"
port="80"
url="http://$user:$pass@$server:$port"
# List of location to log
LOC1="Huston"
LOC2="Hazen"
case $1 in
config)
cat <<'EOM'
graph_title Information
graph_vlabel Number
graph_category Data
Count01.label 01 $LOC1
Count02.label 02 $LOC2
EOM
exit 0;;
esac
# read data into variable
infoservers=`wget -q -O - "$url/folder"`
echo -n "Count1.value "
echo "$infoservers" | grep "|1" | grep $LOC1 | wc -l
echo -n "Count2.value "
echo "$infoservers" | grep "|1" | grep $LOC2 | wc -l
Output
Count1.value 3
Count2.value 2
This list number of |1 in table from the data I like to get value from.
I have tried to make a loop to do the same, so I do not need to add more lines than the location to look at. I can not get script to show value.
for i in `seq 1 2`;
do
echo -n "Count${i}.value "
echo "$infoservers" | grep "|1" | grep $LOC${i} | wc -l
done