Run shell script from launcher with root permissions


I have a shell script that runs a GUI application on Ubuntu 12.04.



The way I'm currently running the application is that I open the terminal and go to the directory that contains that file, then do sudo ./shellScriptFileName which runs just fine, however I have two problems, one is that this takes so much time so I would like to add a shortcut in the launcher, second is that the terminal needs to stay open, which is a pain (hopefully this won't be a problem after I'm able to run it from the launcher.



Clarification: I would like for the terminal to be closed when my application starts running.



It seems that you haven't got this issue done yet, have you visited the "how to" link which I provided in the comment above? Click Me



If you check that you should get this problem solved in several ways, cool and nice.
To be simple, I'd like to recommend a "dummy" way to make it works for you.




  1. Open your terminal and type sudo apt-get install gnome-panel

  2. When the installation is done, type gnome-desktop-item-edit --create-new ~/Desktop, this command will display a popup "Create launcher" dialog, shown as below



    customize your settings(Name,Command,Icon etc.)


  3. After step 2, you will get a shortcut(it is actually named *.desktop, depends on your setting), feel free to put it in any folder you wish, then drag and drop it to the launcher.



That's it, enjoy your new baked shortcut :-), hope it helps.


Here are the steps:



1. Creating the interactive caller script



Since you want to execute the script and then have the terminal remain in an interactive mode, we need to use a special caller script, which in turn requires expect. We'll assume the script you want to execute is called test.sh




  • Install expect with sudo apt-get -y install expect

  • Create the caller script with this format:




    #!/usr/bin/expect -f

    spawn -noecho bash # create a shell
    expect "$ " # wait for prompt
    send "cd /path to script\n" # your script directory
    send "./test.sh\n" # your script name
    interact # switch to interactive mode

  • Make the caller script, say call_test.sh, executable with



    sudo chmod +x /path/to/call_test.sh




2. Creating the Launcher




  • Press Alt+F2, and type gksudo gedit /usr/share/applications/TestSH.desktop, where TestSH is whatever you want to call your launcher icon.

  • The file is of the following form:




    [Desktop Entry]
    Version=1.0 # your script version
    Type=Application
    Terminal=true # you want a terminal, so...
    StartupNotify=true
    Icon= # can be a built-in (/usr/share/icons)
    # or a custom file, SVG or PNG
    Name=TestSH # Whatever you want to call it
    Comment= # description
    Exec=/path/to/call-test.sh # Path to caller script
    Categories=Application;

  • Finally, make sure the actual script is executable, with sudo chmod +x /path/to/test.sh


  • Close the editor, and search for "TestSH" (script name) in the HUD; you will see the icon, which you can click on, and also drag to the launcher or desktop to add it there.


Making the terminal stay open afterwards is not a very smooth process, but here is what I suggest:



Make a new script with the following contents: gksudo /path/to/shell/script and save it to your desktop. Add the terminal to the launcher. To open the program, open the terminal from the launcher and clik'n'drag the script from the desktop to the terminal.



Or, if you don't necessarily need the terminal open after the program is finished, make a script as above, save it to any directory, and follow this guide to turn it into a launcher icon: http://ubuntuforums.org/showthread.php?t=1700605



I wish that process were a bit smoother, but hey, that's why I use Kubuntu...


Source: http://askubuntu.com/questions/138705/run-shell-script-from-launcher-with-root-permissions

More

  • Dell Inspiron 1210 mini Blank Screen on boot 12.04
    Dell Inspiron 1210 mini Blank Screen on boot 12.04If I mash buttons I get to a gray screen then the login screen and into the desktop but normally I turn on the laptop and I see a black screen with a cursor then a purple screen then it just goes black. I can hit ctrl alt F1 or F2 and get a prompt. I've tried using the poulsbo ppa driver
  • What can I do? Error upgrading libreoffice-core in oneiric-updates
    ubuntu @ ubuntu: ~ $ sudo apt-get-f installReading package lists ... doneBuilding dependency treeReading state information ... doneCorrecting dependencies ... readyThe following packages will be installed extras: LibreOffice-coreWill update the following packages: LibreOffice-core1 upgraded, 0 newly installed, 0 to remove and 411 not
  • No dhcpd3 after installing dhcp3-server
    I wasnted to create a wifi access point using my laptop, for which I need dhcpd3. Even after installing the isc-dhcp-server and dhcp3-server packages, I still can;t run dhcpd3.What gives?Digvijay
  • Weird networking issue under 12.04
    I am having problems with networking in the command line, specifically with the gem installer (I had similar issues yesterday but can't remember exactly what with).So, I am getting:pete@pete-Latitude-E6510:~$ sudo gem install bundler[sudo] password for pete: ERROR: While executing gem ...
  • Run shell script from launcher with root permissions
    I have a shell script that runs a GUI application on Ubuntu 12.04.The way I'm currently running the application is that I open the terminal and go to the directory that contains that file, then do sudo ./shellScriptFileName which runs just fine, however I have two problems, one is that this takes so much time so I would like to add a
  • unable to upgrade to ubuntu 12.4 for Dell Vosto V131
    I am running Ubuntu 11.10 on Vosto V131 and not able to upgrade to 12.4. I tried several times to do it through 'Update Manager' but failed. I tried from a terminal using: sudo apt-get update && sudo apt-get upgrade then do-release-upgrade and got the following error:authenticate 'precise.tar.gz' against 'precise.tar.gz.gpg'
  • What can I do? Error upgrading libreoffice-core in oneiric-updates
    ubuntu @ ubuntu: ~ $ sudo apt-get-f installReading package lists ... doneBuilding dependency treeReading state information ... doneCorrecting dependencies ... readyThe following packages will be installed extras: LibreOffice-coreWill update the following packages: LibreOffice-core1 upgraded, 0 newly installed, 0 to remove and 411 not
  • CD rom driver not installed, cant find driver [closed]
    I have a sony vaio. The model # is PCG 6R3L. First I have went on Sony's site and they dont have anything for my model #. In fact they dont even show it at all. The problem is is that I had the hard drive replaced and I can no longer burn any music to a cdr. Everything else works great. I have an external hard drive with a ton of music
  • How do I get the Broadcom STA wireless driver to load in Ubuntu 12.04? This is on an Inspiron 1721
    When I try to activate it a jockey.log is created. This is the internal wireless that worked in Ubuntu 11.10. Doesn't now that I upgraded to Ubuntu 12.04. I'm using a USB wi-fi for now. If you can connect to the internet using eternet cable, the try this command:sudo apt-get install bcmwl-kernel-sourceA restart will be required after
  • Run shell script from launcher with root permissions
    I have a shell script that runs a GUI application on Ubuntu 12.04.The way I'm currently running the application is that I open the terminal and go to the directory that contains that file, then do sudo ./shellScriptFileName which runs just fine, however I have two problems, one is that this takes so much time so I would like to add a
  • Keep the same Ubuntu boot screen while keeping a desktop package
    I have Ubuntu 10.04 .Just after installing Ubuntu, I installed all the desktop packages except lubuntu.Then when I restarted the computer, Ubuntu shows the Kubuntu boot screen when I restart the computer.Next I uninstalled all the desktop packages except ubuntu-desktop. The boot screen changed back to the Ubuntu one.So how can I retain the
  • Backlight problems with 12.04 on my Acer Aspire 4736z
    How can I fix a bug that wouldn't let me turn the backlight on after it turns off automatically when I close the lid or when powersave settings kick in?I also can't adjust the brightness of the screen through the Fn + Left/Right Arrow button combination, how can I make this work?And one last thing, when I try to follow some of the fixes
  • Blender not working on Ubuntu 11.10 64bit
    I recently installed blender via apt-get on Ubuntu 11.10 64 bit, but whenever I try to start it, nothing happens. I tried via xterm but all it showed was "Segmentation fault" before terminating. Any help on the topic would be appreciated. I think Blender only works with 32 bit, but if it doesn't work with 64 bit as you said you should
  • User menu in Gnome Shell (Gnome 3.4) - entries missing
    For example there is no logout button:If I log in with the guest session, everything seems to be fine (there is a log out button). I tried to remove my whole user directory and create an empty one, but the problem remains.I am running Gnome Shell 3.4 using the PPAs ppa:gnome3-team/gnome3 and ppa:ricotz/testing as described in this answer. I
  • Keep the same Ubuntu boot screen while keeping a desktop package
    I have Ubuntu 10.04 .Just after installing Ubuntu, I installed all the desktop packages except lubuntu.Then when I restarted the computer, Ubuntu shows the Kubuntu boot screen when I restart the computer.Next I uninstalled all the desktop packages except ubuntu-desktop. The boot screen changed back to the Ubuntu one.So how can I retain the