Welcome to the Linux Foundation Forum!

Run script as root after X starts

Hello fellow sysadmins

The problem im having is my laptop will boot up without anyone keyboard backlight but with screen at max brightness. As soon as X starts and I get the login screen, my keyboard backlight is at full brightness too.

I found the "echo # > " one liner that works well on tuning my screen brightness and keyboard brightness, but it does have an effect if I add it to rc.local because X starts and everything gets reset. I've tried putting a sleep in my screen and running it in the background so rc.local can execute, the x session can start and I can login and the timer would be up and the script would run, but no luck.

The distro im currently using is Ubuntu. After I can get Ubuntu to run on this laptop the way I want it, im going to move onto other distros. So what I really need to know is how do I run a script after login but AS ROOT because these commands request root to be able to echo the value to the acpi_video0/brightness file or keyboard backlight file.

Any help would be great. Spent two days on this already and havent gotten anywhere.

Comments

  • Posts: 1
    I know the topic is old, but I thought it best not to leave it without a solution, since I found information closely related to this problem to be sparce.
    The text file which contains the value (1-100) of screen brightness on the laptop of the OP should be at /sys/class/backlight/acpi_video0/brightness. A working solution for systems still running init is easily found with some googling.
    If you have a system with systemd, you have to create an rc.local script at the following path: /usr/local/sbin/rc.local
    It should contain a delayed echo to the brightness file, which will run in the background, such as this:
    1. (sleep 15 ; echo "40" > /sys/class/backlight/acpi_video0/brightness)&
    It will run as root, so no worries. Also, don't forget to make it executable. To do that, open a console and run:
    1. sudo chmod +x /usr/local/sbin/rc.local
    .
    Now, you need to create a systemd service file which will invoke your rc.local script. Create it with this path: /etc/systemd/system/rc-local.service
    and with the the following content:
    1. [Unit]
    2. Description=/etc/rc.local Compatibility
    3. ConditionFileIsExecutable=/usr/local/sbin/rc.local
    4.  
    5. [Service]
    6. Type=oneshot
    7. ExecStart=/usr/local/sbin/rc.local
    8. TimeoutSec=0
    9. StandardOutput=tty
    10. RemainAfterExit=yes
    11. SysVStartPriority=99
    12.  
    13. [Install]
    14. WantedBy=multi-user.target
    Lastly, enable the service:
    1. sudo systemctl enable rc-local
    Reboot and be happy.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training