On Ubuntu there must be several "autoexec.bat" equivalents as I can see files like rc.local which seem to do very little because the comments in the file says it doesn't work by default and I tried putting this command in there and it didn't work.

What I need to know is where I place this line.

echo 0 | /usr/bin/tee -a /sys/class/leds/smc::kbd_backlight/brightness

I also saw a rc.local in /etc/init.d as well but where I would place the cmd to make it work is a mystery as there are two functions in there so do I place it at the end of one of those functions or at the last line?

The command needs root permission to run and ideally it should be executed when the computer starts. As the command dims the keyboard of my MacBook Air.

Also, I would also like to know what file I'd need to edit if only a specific user would have this command run. As its an root command and I don't want to give admin or sudo access to that user I would like this command to execute as root when the user logs in and the user cannot stop that command from running.

Additional Discoveries
$HOME/.profile is the login script but doesn't run as root, it works if you sudo the command but thats not want I need.

The /etc/profileis weird, it doesn't execute at boot but when I go into a shell and execute sudo -i" it runs as soon as the sudo goes into interactive mode

A neat short cut
With version 14.04, might have worked in earlier versions, you simply add a line to crontab using sudo crontab -e and add a line "@reboot whatevercommandwithfullpath" and it works. But with this new version I created a upstart script which is closer to how it should be done.

  • /etc/profile is not supposed to execute at boot. It runs for all Bourne-style login shells, when the shells start. So, it runs together with .profile files in users' home directories. Mar 27, 2013 at 5:13

5 Answers 5


You can create a daemon witch is the right way to do it. However it's a little harder than rc.local.

see here : https://superuser.com/questions/530071/installing-daemon-on-a-fresh-ubuntu-system

detailed help (you can take example of /etc/init.d/hostname) :

copy the skeleton :

sudo cp /etc/init.d/skeleton /etc/init.d/keyboard_backlight

edit the skeleton :

sudo nano /etc/init.d/keyboard_backlight

search for this

        # Return
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
                || return 1
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
                $DAEMON_ARGS \
                || return 2
        # Add code here, if necessary, that waits for the process to be ready
        # to handle requests from services started subsequently which depend
        # on this one.  As a last resort, sleep for some time.


and change it like this :

        echo 0 | /usr/bin/tee -a /sys/class/leds/smc::kbd_backlight/brightness

Comment out or delete the lines inside the do_stop and the do_reload


Save the file.

Give the execution permission to the file :

sudo chmod 755 /etc/init.d/keyboard_backlight

Test your service :

sudo /etc/init.d/keyboard_backlight start

If everything ok, load your service for startup

sudo update-rc.d keyboard_backlight defaults 99

Best regards.


Maybe, for login shells they run in this order:

2./etc/profile.d/ files

However, I'm unsure if the /etc/profile gets executed before any users actually login but it is worth trying just in case I am right.


Is this still working?

This script will run before the graphical interface appears...

  1. Make the script with desired commands. vi file.sh

  2. Copy the script to /etc/init.d cp file.sh /etc/init.d/file.sh

  3. Change permission to allow execution chmod +x /etc/init.d/file.sh

  4. At /etc/init.d Link it! sudo update-rc.d file.sh start 99 2 . (do not forget the "." at the end of the command)

If you need to disable this script in a near future: sudo update-rc.d -f file.sh remove

It seems quite easy this way and you can keep different scripts for different things


most probably you are looking for /etc/rc.local

if you add any command before exit 0 that should run as root.

Don't forget to change permisson to executable for both /etc/rc.local and /etc/init.d/rc.local unless it won't work, leave as is if they are already executable.

  • Did that already, I mentioned that in my original question. Command executes as I redirected output to my home directory so I know it executed. But the command itself didn't dim the keyboard :(
    – Meer Borg
    Mar 16, 2013 at 18:37

Let's say that you have a working script (with the right file permissions), with the name myscript.sh;

cd to to the folder that you have the script in and do:

sudo cp myscript.sh     /etc/profile.d/

This will copy the script to a place that contains scripts that are executed on boot so that the next time you boot it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.