2

I need to run the gnome-terminal with some command with sudo rights on the startup. How could I do that?

  • Don't you mean you need to run a command? Why do you think you need to run the terminal emulator? – ChanganAuto Apr 26 '22 at 19:20
  • I need to see all the outputs of the scripts for debug. That's why I'm I'm running the commands inside the gnome-terminal – Pavlo Sharhan Apr 26 '22 at 19:22
  • You can read your logs anytime. AFAIK any software/process can be added to the startup apps but adding a terminal and running a command automatically isn't. And if just debugging you can open it yourself and run the command or script, don't you? – ChanganAuto Apr 26 '22 at 19:26
  • I am already able to add a terminal to the startup apps and run a command automatically. I've added this command to the startup applications:

    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:28
  • seems I've nailed it The command for the gnome terminal will look like this:

    gnome-terminal -- sh -c 'echo "YOURPASSWORD" | sudo -S sh PATH_TO_YOUR_SCRIPT && sleep 1 && printf "\n"'

    – Pavlo Sharhan Apr 26 '22 at 21:47
  • 1
    You certainly do not need to do that. Instead, tell us what you really want to achieve. Do not ask about what you think is the solution to your problem, ask us about your actual problem. – vanadium Apr 27 '22 at 08:44

1 Answers1

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.

  • 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