This output is generated by following script. issue is somehow signal strength is not displayed. can some one help me to fix this script ? I tried to paste in code format. some how its not formatting correctly so image is pasted.
So, this is a grep or awk inquiry - and not OpenWrt-specific. Someone should be able to answer before possible marked as off topic (from OpenWrt). I'm not a guru with those commands.
Does the command produce the correct answer at the system prompt?
I tested this just for you: https://omnifile.co/ocr/
Seems to have some issues with single quotes though. First one was worse though, didn't even recognize hashes.
Note - I tried pasting code in text (code) format, some how its getting broken. now trying triple quote and various format. Here is entire code intext format. Every thing below this line is part of shell script.
#!/bin/sh
Output directory and file (root path of the web server)
for INTERFACE in $(iwinfo | grep ESSID | cut -d' ' -f1); do
# Get clients for this interface
iwinfo $INTERFACE assoclist | while read -r line; do
if echo "$line" | grep -q "dBm"; then
# Extract MAC and signal strength
MAC=$(echo "$line" | awk '{print $1}')
SIGNAL=$(echo $line | awk {'print $2'})
# Get hostname and IP from DHCP leases
DHCP_INFO=$(grep -i "$MAC" /tmp/dhcp.leases)
if [ ! -z "$DHCP_INFO" ]; then
IP=$(echo "$DHCP_INFO" | awk '{print $3}')
HOSTNAME=$(echo "$DHCP_INFO" | awk '{print $4}')
[ "$HOSTNAME" = "*" ] && HOSTNAME=$(echo "$MAC" | sed 's/://g')
else
IP="Unknown"
HOSTNAME=$(echo "$MAC" | sed 's/://g')
fi
# Format signal strength with color coding
if [ ! -z "$SIGNAL" ]; then
if [ $SIGNAL -ge -50 ]; then
SIGNAL_DISPLAY="<span class='good-signal'>${SIGNAL} dBm</span>"
elif [ $SIGNAL -ge -70 ]; then
SIGNAL_DISPLAY="<span class='medium-signal'>${SIGNAL} dBm</span>"
else
SIGNAL_DISPLAY="<span class='poor-signal'>${SIGNAL} dBm</span>"
fi
else
SIGNAL_DISPLAY="<span class='unknown'>No Signal</span>"
fi
# Add row to the HTML table
echo "<tr><td>$HOSTNAME</td><td>$IP</td><td>$SIGNAL_DISPLAY</td></tr>" >> $OUTPUT_FILE
fi
done
It would be great if you kindly post the whole final script, formatted as already asked... I'm adjusting it for my dumb AP (i.g. no /tmp/dhcp.leases) and pretty close to the goal, but having trouble with the html output formatting (not a developer here...). Thanks a lot.