Starting .sh script at boot breaks LED & reboot

Im Afraid The $ Made No Difference

It's a &, not a $

1 Like

sorry been looking at symbols all day haha

This Causes The Script To No Longer Run At All

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

/sbin/btwifi.sh &

exit 0

Keep in mind that anything that runs as a startup script will be run headless, so the echo commands won't work properly -- you may want to replace those with logger commands.

Also...

Is this running on 17.01? And if so, is this running the official LEDE release or is it a vendor customized version? If the latter, that may change how some of this stuff works.

Please run the following commands (copy-paste the whole block) and paste the output here, using the "Preformatted text </> " button:
grafik

ubus call system board

All Should Be Official, i also have x2 bt home hub 5a and TP-Link WR2543ND Both Running 19.07.9, just using This D-Link To Test With, Its On 17.x as 19.x wouldn't save config after reboot (low storage device)

Output

root@LEDE:~# ubus call system board
{
        "kernel": "4.4.182",
        "hostname": "LEDE",
        "system": "Ralink RT3052 id:1 rev:3",
        "model": "D-Link DIR-615 D",
        "board_name": "dir-615-d",
        "release": {
                "distribution": "LEDE",
                "version": "17.01.7",
                "revision": "r4030-6028f00df0",
                "codename": "reboot",
                "target": "ramips\/rt305x",
                "description": "LEDE Reboot 17.01.7 r4030-6028f00df0"
        }
}

It would be wise to use a newer device with the ability to run a modern version of OpenWrt. LEDE has been EOL for many years now, and is unsupported and has many actively exploited/exploitable vulnerabilities, and really shouldn't be used on the internet anymore.

While we're talking about that... 19.07.10 was just released and that is the final release of the 19.07 series releases and it is officially EOL. It is no longer supported in terms of updates/bug-fixes/security patches (although obviously forum support continues). Consider upgrading your other devices to 21.02 if possible.

I'm sure people here will still give you a best-effort attempt to help resolve your issue, but given the age of LEDE as an OS, it is possible there are nuances that people will not remember.

2 Likes

Will Update One Hub 5a (128/218) to 19.10 & The Other To 20.03, i did try both (i think) 20.01 & 20.02 And they resulted in lower wifi performance, i think the tp link will be stuck on 19.x, not sure if i tried 20.x, think maybe decided to roll back too on there (8/64 device) , Yhe the dlink i bought in 2014, came with DDWRT with a 2013 build on it, used that for a few years, Will see on newer openwrt & see :slight_smile:

Infinite loop in the script.
Thee boot script should do something then end.
For example start another script in the background

so results with testing, 20.x on TP Link, 10 Mbps Slower Download Throughput vs 19.x, simmilar with BT Hubs But Not As Bad, Will Have To Try 19 again on d-link but not hopeful here, ill probably stick with 19.10 for now :slight_smile:

Something Like This?

#!/bin/sh

echo "This script is about to run another script."
sh /sbin/btwifi.sh
echo "This script has just run another script."

Add an & to this line

Like this

sh /sbin/btwifi.sh &

1 Like

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.