[SOLVED] How to run CLI command / script during system startup / boot time ?

Help for Current Versions of MX
When asking for help, use Quick System Info from MX Tools. It will be properly formatted using the following steps.
1. Click on Quick System Info in MX Tools
2. Right click in your post and paste.
Message
Author
User avatar
beng
Posts: 6
Joined: Tue Apr 30, 2024 11:49 pm

[SOLVED] How to run CLI command / script during system startup / boot time ?

#1 Post by beng »

Hi, I want to run this command line command automatically during system startup:

Code: Select all

xset led on
This is so that my keyboard backlight LEDs will turn on so that I can see the keys in a darkened room in order to type the password at the login screen.

Can anyone tell me how to get this command to run when the system starts?

I have tried putting it in /etc/rc.local

I have tried putting it in /etc/init.d/rc.local

Both have not worked.

I am using MX Linux 23.3
Last edited by beng on Fri Sep 13, 2024 5:32 am, edited 1 time in total.

User avatar
fehlix
Developer
Posts: 12772
Joined: Wed Apr 11, 2018 5:09 pm

Re: How to run CLI command / script during system startup / boot time ?

#2 Post by fehlix »

Add an autostart entry with a delay
someting like:
sh -c 'sleep 5; xset led on'

User avatar
beng
Posts: 6
Joined: Tue Apr 30, 2024 11:49 pm

Re: How to run CLI command / script during system startup / boot time ?

#3 Post by beng »

fehlix wrote: Thu Sep 12, 2024 11:44 am Add an autostart entry with a delay
someting like:
sh -c 'sleep 5; xset led on'
Thanks for the suggestion. Do you mean the autostart section in the "Session and Startup" tool? That probably would work but that tool only runs things, at the earliest, on login. I want the command to run before login, when the GUI starts and the login screen appears so that I can see the keys to type the password.

User avatar
beng
Posts: 6
Joined: Tue Apr 30, 2024 11:49 pm

Re: How to run CLI command / script during system startup / boot time ?

#4 Post by beng »

SOLVED:
I found a workaround:
I did a man lightdm to find out more about the display manager. The man information said at the bottom:

Code: Select all

FILES
       /etc/lightdm/lightdm.conf
              Configuration
I then went to look inside /etc/lightdm/lightdm.conf and saw this line for a script that was not commented out:

Code: Select all

display-setup-script=/usr/local/bin/early-bg
I then went to edit that /usr/local/bin/early-bg script and inserted into it the line:

Code: Select all

/usr/bin/xset led on
I put the path to the xset command as I do not know if /usr/bin is already in the path when this script runs.
The result is that when the login screen appears, my keyboard LEDs light up.

I regard this as a workaround as the /etc/rc.local method is supposed to be the proper way to run scripts or commands at startup but does not seem to work. If anyone knows how to get rc.local to run in MX Linux do let me know.

User avatar
BitJam
Developer
Posts: 2303
Joined: Sat Aug 22, 2009 11:36 pm

Re: [SOLVED] How to run CLI command / script during system startup / boot time ?

#5 Post by BitJam »

The problem is you need xset to run after the X server has started. The /etc/rc.local file is working but it runs before the X server has started and therefore the xset command does nothing. Running xset via the display manager config and early-bg script is the correct solution and not a work-around.
"The first principle is that you must not fool yourself -- and you are the easiest person to fool."

-- Richard Feynman

User avatar
beng
Posts: 6
Joined: Tue Apr 30, 2024 11:49 pm

Re: [SOLVED] How to run CLI command / script during system startup / boot time ?

#6 Post by beng »

BitJam wrote: Fri Sep 13, 2024 6:04 am The problem is you need xset to run after the X server has started. The /etc/rc.local file is working but it runs before the X server has started and therefore the xset command does nothing. Running xset via the display manager config and early-bg script is the correct solution and not a work-around.
Thanks for that insight. That helps me understand why the rc.local method did not work.

Post Reply

Return to “MX Help”