Ubuntu – make this keyboard light command that requires sudo run at startup

command linekeyboardstartup

My laptop has a light under the keyboard. I doubt the keyboard light consumes a lot of power, but when it comes to laptops and batteries, every little bit helps. So I prefer it to default to being off.

I found this command that I can run at the command line which switches off the keyboard light:

echo 0 | sudo tee /sys/class/leds/asus::kbd_backlight/brightness

Which is nice, but I'd like to have it in my list of startup programs so that I don't have to remember to turn off the keyboard light, which I often forget to do.

However, it doesn't seem to work if I put it in the startup applications, and I suspect that it could be because part of it requires sudo, so it probably doesn't have the right persmissions at startup time. Or maybe it's another issue. In any case, it doesn't run at startup.

Is there a way I can get this command to run at startup?

Best Answer

Is there a way I can get this command to run at startup?

Yes,

you can add this command in rc.local file in order to be executed in ever system boot/or reboot.

Edit the file, you will need root privileges for that.

gksudo gedit /etc/rc.local 

and add the command line before exit 0

The file should read

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo 0 > /sys/class/leds/asus::kbd_backlight/brightness
exit 0

save the file and reboot to check the results. No sudo is needed here, because the file is executed by the root user.

I don't remember what the execution bits are by default (in Ubuntu) at this file, but you can add the execution bit with the following command

sudo chmod +x /etc/rc.local
Related Question