Starting .sh script at boot breaks LED & reboot

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

Again, you never used the & .

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.

2 Likes

I tried both In RC.local
"/sbin/btstartup.sh" And "sh /sbin/btstartup.sh &"

With both these lines tried
"sh /sbin/btwifi.sh" And "sh /sbin/btwifi.sh &"

They only seem to work without & as adding to either ONE of these lines causes it not to run at boot at all

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.

2 Likes

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?

Well, yes, change PINGURL to 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>

Yes, because your script wasn't working correctly and was just hammering the login-servers.

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 )

hu Apr 28 14:06:21 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:23 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:25 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:27 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:29 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:31 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:33 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:35 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:37 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:39 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:41 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:43 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:45 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:47 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:50 2022 user.notice btwifi: Offline, attempting login
Thu Apr 28 14:06:50 2022 user.notice btwifi: Offline, attempting login URL 1
Thu Apr 28 14:06:51 2022 kern.info kernel: [ 1958.787205] do_page_fault(): sending SIGSEGV to wget for invalid read access from 00000084
Thu Apr 28 14:06:51 2022 kern.info kernel: [ 1958.796599] epc = 77ee4de9 in libubox.so[77ee0000+17000]
Thu Apr 28 14:06:51 2022 kern.info kernel: [ 1958.802677] ra  = 77ea8f27 in libustream-ssl.so[77ea8000+11000]
Thu Apr 28 14:06:53 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:55 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:57 2022 user.notice btwifi: Online Already
Thu Apr 28 14:06:59 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:01 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:03 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:05 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:07 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:09 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:12 2022 user.notice btwifi: Offline, attempting login
Thu Apr 28 14:07:12 2022 user.notice btwifi: Offline, attempting login URL 1
Thu Apr 28 14:07:13 2022 kern.info kernel: [ 1980.957353] do_page_fault(): sending SIGSEGV to wget for invalid read access from 00000084
Thu Apr 28 14:07:13 2022 kern.info kernel: [ 1980.966515] epc = 77e56de9 in libubox.so[77e52000+17000]
Thu Apr 28 14:07:13 2022 kern.info kernel: [ 1980.972084] ra  = 77e1af27 in libustream-ssl.so[77e1a000+11000]
Thu Apr 28 14:07:15 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:17 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:19 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:21 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:23 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:25 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:27 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:29 2022 user.notice btwifi: Online Already
Thu Apr 28 14:07:32 2022 user.notice btwifi: Online Already

Ping Results

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
Request timed out.
Request timed out.
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=35ms 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=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
Reply from 13.224.128.2: bytes=32 time=32ms TTL=241
Reply from 13.224.128.2: bytes=32 time=35ms TTL=241
Reply from 13.224.128.2: bytes=32 time=32ms 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=31ms TTL=241
Request timed out.
Request timed out.
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=58ms TTL=241

Full Script

#!/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/btwifi.sh

# BTWifi Openwrt Autologin Script
# By: Aidan Macgregor (April 2022)
# https://github.com/aidanmacgregor/BT_Wi-Fi_Autologin_MACRODROID-WISPr-HTTP_POST-HTTP_GET-OpenWRT

# 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" = "" ] 
		then
		logger -t btwifi "Offline, attempting login"
		if [ "$ACCOUNTTYPE" = "1" ]
		then
		logger -t btwifi "Offline, attempting login URL 1"
		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
			logger -t btwifi "Offline, attempting login URL2"
			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
				logger -t btwifi "Offline, attempting login URL3"
				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
					logger -t btwifi "Online Already"
fi 
else
logger -t btwifi "Online Already"
fi
sleep 1
done

Ah, apparently Busybox's ping doesn't work the same as it does on the desktop. Change -w 1 to -W 1 and it'll work like it's supposed to.

Kind of annoying, though. I have no idea why Busybox-devs have decided to go with non-standard behaviour.

1 Like

Reduced functionality allows for reduced size

Obviously, but it's not reduced functionality in this case.

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.

2 Likes

Inexcusable, yes, but also entirely to be expected...

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)

  • Look Control LED openWRT script led.sh

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

My Script

#!/bin/sh

######## settings ########

ACCOUNTTYPE=1
USERNAME=
PASSWORD=

######## OPTIONAL ########

PINGDNS=8.8.8.8
PING2URL=www.google.com

######## DO NOT EDIT BELOW HERE ########
while :
do
pingtime=$(ping -c 1 -W 1 $PINGDNS | grep ttl)
	if [ "$pingtime" = "" ] 
	then 
		logger -t BTWi-fi "Ping 1 DNS Fail"
		pingtimetwo=$(ping -c 1 -W 1 $PING2URL | grep ttl) 
		if [ "$pingtimetwo" = "" ] 
		then
			logger -t BTWi-fi "Offline, Attempting Login, Ping 2 DNS Fail"
			if [ "$ACCOUNTTYPE" = "1" ]
			then
				logger -t BTWi-fi "Offline, attempting login URL 1 (BT Home Broadband Account)"
				wget -T 2 -O /dev/null --post-data "username=$USERNAME&password=$PASSWORD" 'https://192.168.23.21:8443/tbbLogon'
			elif [ "$ACCOUNTTYPE" = "2" ]
			then
				logger -t BTWi-fi "Offline, attempting login URL2 (BT Buisness Broadband Account)"
				wget -T 2 -O /dev/null --post-data "username=$USERNAME&password=$PASSWORD" 'https://192.168.23.21:8443/ante?partnerNetwork=btb'
			elif [ "$ACCOUNTTYPE" = "3" ]
			then
				logger -t BTWi-fi "Offline, attempting login URL3 (BT Wi-fi Account)"
				wget -T 2 -O /dev/null --post-data "username=$USERNAME&password=$PASSWORD" 'https://192.168.23.21:8443/ante'
			fi
		fi 
	fi
sleep 1
done

Your Adjustments:

######## 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 
		logger -t BTWi-fi "Ping 1 DNS Fail"
		if ! ping -c 1 -W 1 $PING2URL 2>/dev/null >/dev/null
		then
			PREVIOUS_STATUS="OFFLINE"
			logger -t BTWi-fi "Offline, Attempting Login, Ping 2 DNS Fail"
			if [ "$ACCOUNTTYPE" = "1" ]
			then
				logger -t BTWi-fi "Offline, attempting login URL 1 (BT Home Broadband Account)"
				wget -T 2 -O /dev/null --post-data "username=$USERNAME&password=$PASSWORD" 'https://192.168.23.21:8443/tbbLogon'
			elif [ "$ACCOUNTTYPE" = "2" ]
			then
				logger -t BTWi-fi "Offline, attempting login URL2 (BT Buisness Broadband Account)"																	 
				wget -T 2 -O /dev/null --post-data "username=$USERNAME&password=$PASSWORD" 'https://192.168.23.21:8443/ante?partnerNetwork=btb'
			elif [ "$ACCOUNTTYPE" = "3" ]
			then
				logger -t BTWi-fi "Offline, attempting login URL3 (BT Wi-fi Account)"														 
				wget -T 2 -O /dev/null --post-data "username=$USERNAME&password=$PASSWORD" 'https://192.168.23.21:8443/ante'
			fi
		else
			if [ "$PREVIOUS_STATUS" = "OFFLINE" ]
			then
				PREVIOUS_STATUS="ONLINE"
			fi
		fi
	else
		if [ "$PREVIOUS_STATUS" = "OFFLINE" ]
		then
			PREVIOUS_STATUS="ONLINE"
		fi
	fi
sleep 1
done

oh although the odd LED behaviour & reset/restart not working still remains :slight_smile:

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.

1 Like