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

  • thcloakthcloak 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:
    (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:
    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:
    [Unit]
    Description=/etc/rc.local Compatibility
    ConditionFileIsExecutable=/usr/local/sbin/rc.local
    
    [Service]
    Type=oneshot
    ExecStart=/usr/local/sbin/rc.local
    TimeoutSec=0
    StandardOutput=tty
    RemainAfterExit=yes
    SysVStartPriority=99
    
    [Install]
    WantedBy=multi-user.target 
    
    Lastly, enable the service:
    sudo systemctl enable rc-local
    
    Reboot and be happy.
Sign In or Register to comment.