Automatically running commands (or a script file) after login

This post is in reference to my previous post about automatically running a script at boot-up. The previous post is here.

With dmt’s help, I was able to create a systemd service to run a script at boot-up to turn on the keyboard backlight on my laptop.

The systemd service works 100% of the time to successfully execute the script file. There is no problem there.

The script file runs this configuration tool called “msi-perkeyrgb” with the parameters below to turn on the keyboard backlight. “--model” and “--id” below include a specific information particular to my laptop.

msi-perkeyrgb --model GS75 --id 1038:113a -s f22c46

and the following command below turns on the keyboard backlight.

echo ‘3-12’ > /sys/bus/usb/drivers/usb/unbind

90% of the time, it works and keyboard backlight lights up at boot-up. But 1 out of 10 boot-ups, the keyboard backlight does not light up, most probably, due to a problem with the configuration tool, “msi-perkeyrgb”. Who knows!?! When that happens, I reset the “bind” state running the command below.

sudo su
echo '3-12' > /sys/bus/usb/drivers/usb/bind

and then “unbind” again as shown below to manually turn on the keyboard backlight .

echo ‘3-12’ > /sys/bus/usb/drivers/usb/unbind

Here is my question; since 1 of out 10 boot-ups, I run into this problem that the keyboard backlight doesn’t light up. Is there a way to automatically run the commands below right after “login” (after Manjaro boots up to desktop environment)?

sudo su
echo ‘3-12’ > /sys/bus/usb/drivers/usb/bind
echo ‘3-12’ > /sys/bus/usb/drivers/usb/unbind

Under “Startup and Shutdown”, there is an option to add applications to auto-start them. And “Autostart” works with applications, but even though there is an option to add a “Login Script” to “Autostart”, the login script does not work. Any help, solution or workaround is greatly appreciated. Thank you.

The reason your current service is flaky may root in the fact that keyboard has not yet been enumerated by udev.

You could set the service to wait before executing e.g. 15s

[Service]
ExecStartPre=/bin/sleep 15
1 Like

Thank you, linux-aarhus, for your reply and help!

By coincidence, I think I figured out as to why the keyboard backlight is not lighting up at every boot-up.

It is because, for some “unknown” reason, Manjaro is not detecting (or mounting) the HID device, which is the “MSI SteelSeries keyboard” device in this case. But the question is; if it is not detecting the device, how come the keyboard still works to type stuff??? When Manjaro randomly doesn’t detect the “MSI SteelSeries keyboard” device, the only thing that doesn’t work about it is the keyboard backlight. Why would Manjaro randomly not detect the HID device? Is there any way to solve this issue?

systemd uses udev to enumerate devices - the order is completely arbitrary - which is why I suggested the delayed execution.

1 Like