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

I need to run a python script in a terminal, at startup (on Lubunt). This script requires root.

I've setup a .desktop file that runs the following command:

lxterminal --command="python /home/d/Jarvis/ && /bin/bash"

The terminal window opens at startup and runs the script, but then closes when the Python script returns an error (because it's not being run as root). When I change the Exec= to this...

lxterminal --command="sudo python /home/d/Jarvis/ && /bin/bash"

... (prefixing command with 'sudo') which works. However, the terminal opens on startup and displays the

[sudo] password for d: \

prompt, requiring me to input my password. I would like the execution of the python script at startup to be completely automatic with no user interaction.

How can I accomplish this?

share|improve this question
up vote 5 down vote accepted

If you want it at login and not startup (as I don't see how LXTerminal can be opened without X server being up), you have to add an exception to the /etc/sudoers file so that you won't be prompted for your password.

To do this, run sudo visudo and then add the following:

<your username> ALL = NOPASSWD: /home/d/Jarvis/

Make sure that you add this at the end of the file for this to work. I would also set the permissions of to executable for this to work. So, do this to set it as executable:

chmod +x /home/d/Jarvis/

Hope it helps!

share|improve this answer
This works! Thank you so much! I still have one issue... When I run "" instead of "python", I get 'import: not found' errors for core python modules (ex. datetime). I don't think I'm able to copy those modules into /Jarvis/, so what do I do? – Brandon Oct 7 '12 at 21:20
@Brandon You might have to set the PYTHONPATH variable, but this is just a guess. For this, I would create a script called '' with the following contents: PYTHONPATH={what ever it should be} sudo /home/d/Jarvis/ I'm really not sure about this, though. Maybe this will help: – kroq-gar78 Oct 7 '12 at 22:24

Custom scripts that get executed on startup as root can be run via rc.local.

Edit /etc/rc.local with root rights:

sudo nano /etc/rc.local

and put the line

python /home/d/Jarvis/

just before the last line, which should say exit 0. Reboot to see if it worked.

share|improve this answer

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.