Score:0

execute script to open terminal to run root commands

us flag

I’m looking to run a shell script by double-clicking it from desktop gui for my ubuntu server (v20).

I would like the shell script to run these commands in a terminal window when I double click it:

  • sudo -i (prompt for password) then under root =
  • xhost +
  • unset XAUTHORITY
  • export DISPLAY=:0
  • ssa -local

it must run in that order as I have to do this so I can run hp ssa under root

I’ve tried all sorts of ways to get it to run, but I cannot. Any help is appreciated!

Thanks

guiverc avatar
cn flag
So this is a Ubuntu Core 20 server install, and not a Ubuntu 20.04 LTS Server install (the 20 is used to signify a *snap* only product, the 20.04 or *year.month* format is used for *deb* based products).
Chris Hudlin avatar
us flag
@guiverc, its just a normal 20.04 install
guiverc avatar
cn flag
Well please say so (ie. edit your question & I can remove my comment(s)), as 20 and 20.04 are different products; Ubuntu uses the *year.month* format for *deb* based products, and *year* format only for specialist *snap* only products (20 has 10 year supported life; longer than 20.04 LTS which has 5 years of *standard* that can be extended an extra 5 years via ESM... the products differ...)
Score:0
cn flag

For Gnome Terminal, which comes with a default Ubuntu install, that can be achieved with a custom profile. In the Preferences dialog, create a new profile, e.g. rootshell. On the "Command" tab of the new profile, specify your shell script as "Custom command". That can be exactly as you hinted to, however preferably include a shebang.

#!/bin/bash
sudo -i
xhost +
unset XAUTHORITY
export DISPLAY=:0
ssa -local

In your .desktop launcher, launch this custom terminal as:

Exec=gnome-terminal --window-with-profile=rootshell

Double-clicking the launcher will start Gnome Terminal with the custom profile. On startup, Gnome Terminal will run the script: your user password is asked to elevate priviledges to root. Subsequent commands are executed, and finally, you are dropped at a root prompt, with an environment customized through your script.

If you use a different terminal emulator, a similar approach will apply in most cases. However, details on how to configure will vary.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.