Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
/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. – Eliah Kagan Mar 27 '13 at 5:13
up vote 2 down vote accepted

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

see here :

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.

share|improve this answer

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.

share|improve this answer

Is this still working?

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

  1. Make the script with desired commands. vi

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

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

  4. At /etc/init.d Link it! sudo update-rc.d 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 remove

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

share|improve this answer

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.

share|improve this answer
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 '13 at 18:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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