Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 15082  / 3 Years ago, thu, september 23, 2021, 8:00:53

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



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



lxterminal --command="python /home/d/Jarvis/alarm.py && /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/alarm.py && /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?


More From » lubuntu

 Answers
4

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/alarm.py


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



chmod +x /home/d/Jarvis/alarm.py


Hope it helps!


[#35096] Friday, September 24, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
finatch

Total Points: 49
Total Questions: 106
Total Answers: 94

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
;