Still Need To Look Into "logger -t" instead of "echo" at some point, so the results are a follows With "&" at the end of either line caused the script to Fail to run at boot, And it doesn't matter if i start "btwifi.sh" directly OR "btstartup.sh" from "rc.local" The Same Behaviour Remains (With this TP-Link the "LOCK" LED flashes continuously like its still stuck in its booting flashing phase Just Link The D-Link & its power flashing like still booting)
What Works (mostly Besides Reset & LEDS)
rc.local
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
/sbin/btstartup.sh
exit 0
And The Startup Script
#!/bin/sh
echo "This script is about to run another script."
sh /sbin/btwifi.sh
echo "This script has just run btwifi.sh"
And For Completeness
#!/bin/sh
######## INFO ########
# OpenWrt:
# wget: SSL support not available, please install the following
# libustream-mbedtls
# Copy To /sbin/ (Use WinSCP & Check Permissions (0777)
# Run Using Putty Or Kitty
# btwifi.sh
# Start On Boot (Add This With LUCI System/Startup)
# /sbin/btstartup.sh
# In The SETTINGS Section Choose Your Account Type & Add Email & Password
# Account Type:
# 1 = BT Home Broadband
# 2 = BT Wi-Fi Account
# 3 = BT Buisness Broadband
######## settings ########
ACCOUNTTYPE=1
USERNAME=
PASSWORD=
######## OPTIONAL ########
PINGDNS=8.8.8.8
PING2URL=www.google.com
######## DO NOT EDIT BELOW HERE ########
while :
do
pingtime=$(ping -w 1 $PINGDNS | grep ttl)
if [ "$pingtime" = "" ]
then
pingtimetwo=$(ping -w 1 $PING2URL | grep ttl)
if [ "$pingtimetwo" = "" ]
echo "Offline, Attempting Login"
then
if [ "$ACCOUNTTYPE" = "1" ]
then
wget --no-check-certificate -T 2 -O /dev/null --post-data "username=$USERNAME&password=$PASSWORD" 'https://192.168.23.21:8443/tbbLogon'
fi
if [ "$ACCOUNTTYPE" = "2" ]
then
wget --no-check-certificate -T 2 -O /dev/null --post-data "username=$USERNAME&password=$PASSWORD" 'https://192.168.23.21:8443/ante'
fi
if [ "$ACCOUNTTYPE" = "3" ]
then
wget --no-check-certificate -T 2 -O /dev/null --post-data "username=$USERNAME&password=$PASSWORD" 'https://192.168.23.21:8443/ante?partnerNetwork=btb'
fi
else
clear ; echo 'Online'
fi
else
clear ; echo 'Online'
fi
sleep 1
done
One of the reasons why you're having troubles could very well be because there are a couple of bugs in that script of yours!
I didn't test this script, I just modified it a little, but this should work and it logs the results to syslog instead of the console:
#!/bin/sh
######## INFO ########
# OpenWrt:
# wget: SSL support not available, please install the following
# libustream-mbedtls
# Copy To /sbin/ (Use WinSCP & Check Permissions (0777)
# Run Using Putty Or Kitty
# btwifi.sh
# Start On Boot (Add This With LUCI System/Startup)
# /sbin/btstartup.sh
# In The SETTINGS Section Choose Your Account Type & Add Email & Password
# Account Type:
# 1 = BT Home Broadband
# 2 = BT Wi-Fi Account
# 3 = BT Buisness Broadband
######## settings ########
ACCOUNTTYPE=1
USERNAME=
PASSWORD=
######## OPTIONAL ########
PINGDNS=8.8.8.8
PING2URL=www.google.com
######## DO NOT EDIT BELOW HERE ########
PREVIOUS_STATUS="OFFLINE"
# Ensure PATH is sensible
export PATH=/usr/sbin:/usr/bin:/sbin:/bin:$PATH
while true
do
if ! ping -c 1 -w 1 $PINGDNS 2>/dev/null >/dev/null
then
if ! ping -c 1 -w 1 $PING2URL 2>/dev/null >/dev/null
then
PREVIOUS_STATUS="OFFLINE"
logger -t btwifi "Offline, attempting login"
if [ "$ACCOUNTTYPE" = "1" ]
then
wget --no-check-certificate -T 2 -O /dev/null --post-data "username=$USERNAME&password=$PASSWORD" 'https://192.168.23.21:8443/tbbLogon'
elif [ "$ACCOUNTTYPE" = "2" ]
then
wget --no-check-certificate -T 2 -O /dev/null --post-data "username=$USERNAME&password=$PASSWORD" 'https://192.168.23.21:8443/ante'
elif [ "$ACCOUNTTYPE" = "3" ]
then
wget --no-check-certificate -T 2 -O /dev/null --post-data "username=$USERNAME&password=$PASSWORD" 'https://192.168.23.21:8443/ante?partnerNetwork=btb'
else
logger -t btwifi 'Online'
fi
else
if [ "$PREVIOUS_STATUS" = "OFFLINE" ]
then
logger -t btwifi "Online"
PREVIOUS_STATUS="ONLINE"
fi
fi
else
if [ "$PREVIOUS_STATUS" = "OFFLINE" ]
then
logger -t btwifi "Online"
PREVIOUS_STATUS="ONLINE"
fi
fi
sleep 1
done
Also, your /etc/rc.local should just contain:
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
/bin/sh /sbin/btwifi.sh &
exit 0
The "/bin/sh" is there in case you forget to make the script executable.
In case you're interested in understanding your bug:
The echo-command is in the wrong place, becoming a part of the if-clause. The echo-command's return-value is different when attempting to print to a TTY and when a TTY is not available, which causes the if-clause to evaluate differently. This is why your script has been working weird.
Obviously, none of this matters, if you use the version I posted above, but I am just explaining this in case you (or anyone else) want to understand.
Thank You Will Try This, And The Explanation Is Very Helpful, my first attempt at a script so learning
Shellcheck On Yours Shows, Main Warning In PING2URL Not Used, Small typo thats easily fixed, and doubl quotes warning (probably not an issue
$ shellcheck myscript
Line 32:
PING2URL=www.google.com
^-- SC2034 (warning): PING2URL appears unused. Verify use (or export if used externally).
Line 38:
export PATH=/usr/sbin:/usr/bin:/sbin:/bin:$PATH
^-- SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
export PATH=/usr/sbin:/usr/bin:/sbin:/bin:"$PATH"
Line 44:
if ! ping -c 1 -w 1 $PINGURL 2>/dev/null >/dev/null
^-- SC2086 (info): Double quote to prevent globbing and word splitting.
^-- SC2153 (info): Possible misspelling: PINGURL may not be assigned. Did you mean PING2URL?
So Far Running Manually it works, although its much slower, before i would miss 2 maybe 3 sometimes ping timeouts (3 seconds MAX) whereas with this script internet is down for over 10 seconds, this would break active downloads & online gaming sessions would be lost, whereas with my current Macrodroid Soloution downloads & games dont error out (about 3 seconds max as well)
See Ping Results
Your Fixed Script:
C:\WINDOWS\system32>ping -t -w 1000 neverssl.com
Pinging neverssl.com [13.224.128.2] with 32 bytes of data:
Reply from 13.224.128.2: bytes=32 time=32ms TTL=241
Reply from 13.224.128.2: bytes=32 time=32ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=32ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=32ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=35ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=33ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=30ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=37ms TTL=241
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=32ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=33ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=30ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=34ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=30ms TTL=241
Reply from 13.224.128.2: bytes=32 time=32ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=34ms TTL=241
Reply from 13.224.128.2: bytes=32 time=33ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=35ms TTL=241
Reply from 13.224.128.2: bytes=32 time=30ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=32ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Reply from 13.224.128.2: bytes=32 time=32ms TTL=241
Reply from 13.224.128.2: bytes=32 time=30ms TTL=241
Reply from 13.224.128.2: bytes=32 time=30ms TTL=241
Reply from 13.224.128.2: bytes=32 time=32ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Reply from 13.224.128.2: bytes=32 time=63ms TTL=241
Reply from 13.224.128.2: bytes=32 time=32ms TTL=241
Reply from 13.224.128.2: bytes=32 time=31ms TTL=241
Ping statistics for 13.224.128.2:
Packets: Sent = 82, Received = 60, Lost = 22 (26% loss),
Approximate round trip times in milli-seconds:
Minimum = 30ms, Maximum = 63ms, Average = 32ms
Control-C
^C
C:\WINDOWS\system32>btwifi.sh
'btwifi.sh' is not recognized as an internal or external command,
operable program or batch file.
OLD SCRIPT:
C:\WINDOWS\system32>ping -t -w 1000 neverssl.com
Pinging neverssl.com [13.224.128.47] with 32 bytes of data:
Reply from 13.224.128.47: bytes=32 time=33ms TTL=241
Reply from 13.224.128.47: bytes=32 time=34ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=33ms TTL=241
Reply from 13.224.128.47: bytes=32 time=36ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=33ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=31ms TTL=241
Reply from 13.224.128.47: bytes=32 time=35ms TTL=241
Reply from 13.224.128.47: bytes=32 time=33ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=33ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Request timed out.
Request timed out.
Reply from 13.224.128.47: bytes=32 time=64ms TTL=241
Reply from 13.224.128.47: bytes=32 time=34ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=38ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=33ms TTL=241
Reply from 13.224.128.47: bytes=32 time=33ms TTL=241
Reply from 13.224.128.47: bytes=32 time=35ms TTL=241
Reply from 13.224.128.47: bytes=32 time=33ms TTL=241
Reply from 13.224.128.47: bytes=32 time=38ms TTL=241
Reply from 13.224.128.47: bytes=32 time=31ms TTL=241
Reply from 13.224.128.47: bytes=32 time=33ms TTL=241
Reply from 13.224.128.47: bytes=32 time=34ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=37ms TTL=241
Request timed out.
Request timed out.
Reply from 13.224.128.47: bytes=32 time=33ms TTL=241
Reply from 13.224.128.47: bytes=32 time=33ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=33ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Reply from 13.224.128.47: bytes=32 time=32ms TTL=241
Ping statistics for 13.224.128.47:
Packets: Sent = 44, Received = 40, Lost = 4 (9% loss),
Approximate round trip times in milli-seconds:
Minimum = 31ms, Maximum = 64ms, Average = 33ms
Control-C
^C
C:\WINDOWS\system32>
it must be possible to speed up the detection, it works as expected with macrodroid, 1 second timeout (check, Check again, And Run login url if fails) all within a 5 second loop, on the original sh it shouldn't be hammering BT Login Servers,
See The Working Macrodroid Implementation Here (Github)
I added logger to the My Original Script (Only Difference), it runs as expected with only reporting online and NOT constantly running the loginURL, see system log (2 Manual Log Outs, both 2 missed pings )
The use of --no-check-certificate is, as you might expect, a severe security issue.
Checking certificates is the foundation of how https protects a user from fake sites designed to obtain secrets intended for the real site. Since certificates are not checked, a hacker could set up a fake "BT Wifi" network with their own server at 192.168.23.21 and when you connect to it, this script will send them your real BT username and password. Since BT is recommending this script be used, that is certainly happening all over the country.
This sort of thing is inexcusable from a real ISP company.
This script is not in any way endorsed or supported by BT, I was using the IPs with macrodroid as this was behind the router with pushed Google DNS instead of the BT supplied servers as BTWifi.com donst resolve on Google's DNS (google DNS to remove forced Google safe search)
Thanks for your input, with the comments so far I have some things tor try and some other ideas, will report back the results soon
Test Alternative Script With -W for ping timeout
Remove online after check message from LOG (or debug switch)
Add BT Hotspot Check Else Sleep 30,
check if 192.168.21.23 is up (btwifi.com still resolves on non BT network), or BT DNS 192.168.22.22 / 192.168.22.23
Switch To Secure URL instead of IP (With Certificate as script won't be behind Google DNS with NX Domain error on the router)
ok so removed no check certificate, changing the -W fixed your script and it now behaves like mine, these are the 2, have a couple of questions, how is the if ! working & also i see your writing output to /dev/null, where as on mine i was using the TTL response as input, where dose this data go if not sent to null & can it build up garbage data and fill storage, not too sure how your ping works?
export PATH=/usr/sbin:/usr/bin:/sbin:/bin:$PATH, this line, from what i can see its about user accounts and having different paths, not entirely sure here, some insight would be awesome,
Also "PREVIOUS_STATUS="OFFLINE"" , is this whole logic not redundant? following the flow of the script if it was removed would it impact the function, as mine is missing it but works the same, are you only using it for the else statement? and i have no else in mine and that doesn't appear to alter behaviour
Applications typically specify a return value that is used to indicate if it was successful or if there was an error. On the command-line, a return value of 0 is typically used to indicate OK/no error/true whereas 1 is the opposite. The return-value can be accessed via $? and that's what the script does: it checks the return-value of the ping-command -- if ping returns a 0, it was successful at pinging and if it returns a 1, ping failed. The exclamation-mark reverses the logic.
In other words, the line basically says if [return-value is NOT true] from the ping-command, then...
The PATH-variable is just simply used by the shell-script to know where to look for the executables. Over the years I've picked up the habit of always making sure it contains some sane values, just in case the PATH-variable was messed up for some reason. If it was, none of the script would work, but since we explicitly set it up with sane defaults, the script'll work even if the original value was wrong.
Also, no, you using the textual output from ping won't "fill storage" or anything. It just goes temporarily into RAM and gets thrown away after the if-clause. Using $? is more reliable, though, and it's also faster to execute.
Finally, the PREVIOUS_STATUS-thing is just there so you can add more logging, if you like. Removing it won't change the functionality of the script.