Rc.local commands not working

Hi,

I have the following code in rc.local but only the code to disable the blue light executes why is this?

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
echo 1 > /sys/devices/platform/leds/leds/bpi-r64:pio:blue/brightness
wait 10
echo 0 > /sys/devices/platform/leds/leds/bpi-r64:pio:green/brightness
exit 0

Thanks,

Aaron

wait != sleep

The wait command likely blocks because it is expecting a background process termination that never happens. You likely meant to „sleep 10“ seconds.

Some more explanation here:

6 Likes

Thanks! However, the same thing happens if I remove the "wait 10" line and just have the lines that disable the light. I try replacing wait with sleep and see if it works though. This does not work either.

echo 1 > /sys/devices/platform/leds/leds/bpi-r64:pio:blue/brightness && echo 0 > /sys/devices/platform/leds/leds/bpi-r64:pio:green/brightness

I think you need to single-quote in this line.

Also: https://linuxhandbook.com/quotes-in-bash/

1 Like

You mean around the whole line?

I'm pretty sure @lleachii meant this:

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
echo "1" > "/sys/devices/platform/leds/leds/bpi-r64:pio:blue/brightness"
sleep 10
echo "0" > "/sys/devices/platform/leds/leds/bpi-r64:pio:green/brightness"
exit 0

If "this doesn't work" means there's no change in LED behaviour, it means either or both of those things:

  1. Commands are wrong (should there be leds/leds/ in there?).
  2. Something is modifying the values above after the rc.local had ran.
1 Like

Do those commands work as you expected if run manually?

If the LED has a trigger set, forcing a value to brightness only has temporary effect until the next triggering event.

1 Like

The commands work as expected if I write/paste them directly into the terminal. @stangri the first line works just not the second one.

Accidental use of windows newlines maybe?

2 Likes

@jow may be right that there could be issues with newlines or other formatting problems.

I'd recommend creating a separate script file and running that manually. When that script works as intended, you can launch that script from rc.local.

1 Like

Another possible explanation is that something alters/resets the LED behavior after rc.local was executed.

3 Likes

Usually there is an LED section in /etc/config/system and if these LEDs are referenced there, configure them there.

Yes, I moved the code to its own script but still the same problem. @mk24 I read the location I referenced in the code is correct according to the Banana Pi R64 documentation.

Please be more specific here -- same problem with rc.local or in general?
Better phrased: does the standalone script execute properly when manually called?

The script version executes but has the same effect as if the code was in rc.local. That is to say only the first line is executed.

That means it is not executing properly.

How are you creating this file? Are you doing this on the computer and transferring it to your router, or did you create it directly on your router (using vi or nano)?

I created the file directly on the pi using nano because I can never remember the ssh command to transfer the file from/to my computer.

ok... so let's try to debug a bit to see where it is failing -- we'll add logger statements

logger "setting blue to 1"
echo "1" > "/sys/devices/platform/leds/leds/bpi-r64:pio:blue/brightness"
logger "sleeping for 10 seconds"
sleep 10
logger "setting green to 0"
echo "0" > "/sys/devices/platform/leds/leds/bpi-r64:pio:green/brightness"
logger "done, exiting"
exit 0

then run that manually and provide the output of the following:

logread -l 10
1 Like

this is the log output

Tue Dec 20 03:34:16 2022 authpriv.info dropbear[4110]: Child connection from 192.168.1.124:57402
Tue Dec 20 03:34:16 2022 authpriv.notice dropbear[4110]: Auth succeeded with blank password for 'root' from 192.168.1.124:57402
Tue Dec 20 03:35:38 2022 daemon.notice wpa_supplicant[1845]: wlan0: CTRL-EVENT-BEACON-LOSS
Tue Dec 20 03:37:00 2022 user.notice root: setting blue to 1
Tue Dec 20 03:37:00 2022 user.notice root: sleeping for 10 seconds
Tue Dec 20 03:37:10 2022 user.notice root: setting green to 0
Tue Dec 20 03:37:10 2022 user.notice root: done, exiting
Tue Dec 20 03:37:11 2022 daemon.notice wpa_supplicant[1845]: wlan0: CTRL-EVENT-BEACON-LOSS
Tue Dec 20 03:37:14 2022 daemon.notice wpa_supplicant[1845]: wlan0: CTRL-EVENT-BEACON-LOSS
Tue Dec 20 03:37:16 2022 daemon.notice wpa_supplicant[1845]: wlan0: CTRL-EVENT-BEACON-LOSS

so this indicates that the script is running to completion.

What is (or is not) happening when you run your script?

what is the output of the following:

cat /sys/devices/platform/leds/leds/bpi-r64:pio:blue/max_brightness
cat /sys/devices/platform/leds/leds/bpi-r64:pio:blue/trigger
cat /sys/devices/platform/leds/leds/bpi-r64:pio:green/max_brightness
cat /sys/devices/platform/leds/leds/bpi-r64:pio:green/trigger
1 Like