Results 1 to 2 of 2
Hi,
I am creating a script that makes remote routers report their status back to a central location. I do however have a problem with constructing the URL that shall ...
- 07-20-2008 #1Just Joined!
- Join Date
- Jul 2008
- Posts
- 4
Setting global variable from within a loop
Hi,
I am creating a script that makes remote routers report their status back to a central location. I do however have a problem with constructing the URL that shall be reported back because the global variable $WGET which is used to build the URL string is not treated as global, but is only updated locally within the loop:
#!/bin/sh
WIFI=ath0
BR=br0
# Update the MAC, IP address and peers of the AP
WGET=http://<mysite>/update.php
IP=`ifconfig $BR | grep inet | cut -d B -f1 | sed s/[^0-9.]//g`
AP=`iwconfig $WIFI | grep Access | cut -d" " -f18`
ESSID=`iwconfig $WIFI | grep ESSID | cut -d\" -f2`
RATE=`iwconfig $WIFI | grep Rate | cut -d"M" -f1 | cut -b20-25 | cut -d" " -f1`
UPTIME=`cat /proc/uptime | cut -d"." -f1`
CLI=`cat /proc/net/arp | grep $BR | wc -l | sed s/[^0-9]//g`
WGET="$WGET?IP=$IP&AP=$AP&ESSID=$ESSID&UPTIME=$UPT IME&CLI=$CLI&RATE=$RATE"
echo $WGET
iwlist $WIFI peers | grep 'Quality' | while read line;
do
MAC=`echo $line | cut -d" " -f1`
QUAL=`echo $line | cut -d"=" -f2 | cut -d"/" -f1`
SIG=`echo $line | cut -d"=" -f3 | cut -d" " -f1`
NOISE=`echo $line | cut -d"=" -f4 | cut -d" " -f1`
WGET="$WGET&MAC[]=$MAC&QUAL[]=$QUAL&SIG[]=$SIG&NOISE[]=$NOISE"
echo $WGET
done
echo $WGET
#wget -O /dev/null "$WGET"
If you run the above script, the $WGET within the loop is updated and shows the complete URL with all peers, but the last $WGET is not getting updated with the contents collected within the loop. Instead, it only shows the contents that was present before the loop was entered.
What can be done to update the last $WGET so it contains info from all peers?
BR
Arne-J.
- 07-20-2008 #2
Hi and Welcome !
Duplicate threads are not allowed. Its against Forum Rules. Please continue at other thread of yours.
Thread Locked.It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First


