I need to run the gnome-terminal with some command with sudo rights on the startup. How could I do that?
Asked
Active
Viewed 1,471 times
1 Answers
0
Several people asking me why do I need to run the script on the startup with the GUI. The answer is - I want to know what's happening on the machine(Jetson Nano with Ubuntu). I need to know if the script running or not, what it does at a moment.
I've found the solution by myself:
the command to run the gnome-terminal on root with some command as an argument will look like this:
gnome-terminal -- sh -c 'echo "YOURPASSWORD" | sudo -S sh PATH_TO_YOUR_SCRIPT && sleep 1 && printf "\n"'
To put it on autostart:
create the file:
nano ~/.config/autostart/gnome-terminal.desktop
input the following :
[Desktop Entry]
Type=Application
Exec=gnome-terminal -- sh -c 'echo "YOURPASSWORD" | sudo -S sh PATH_TO_YOUR_SCRIPT && sleep 1 && printf "\n"'
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_US]=anything
Name=anything
Comment[en_US]=anything
Comment=anything
Then Ctrl+x to save.
Done.

Pavlo Sharhan
- 21
- 2
-
Thanks--this helped me get my own autostarting gnome-terminal going. one minor tip: you don't need to pipe your password to sudo if you update /etc/sudoers to include NOPASSWD for the specific command. – Chris Combs Aug 21 '23 at 17:36
gnome-terminal -- sh /path/to/my/script.sh
I just need to run the terminal with sudo priviliges
– Pavlo Sharhan Apr 26 '22 at 20:28gnome-terminal -- sh -c 'echo "YOURPASSWORD" | sudo -S sh PATH_TO_YOUR_SCRIPT && sleep 1 && printf "\n"'
– Pavlo Sharhan Apr 26 '22 at 21:47