2

My setup is I have a website (www.example.com) that I have uploaded bash scripts to www.example.com/location/of/bash/script.txt

I now would like a Desktop Launcher (.desktop) file that I can use to open the terminal, then proceed to run the script from the website. So far I have created a .desktop file that can open the terminal but not successfully run the script from the URL.

My command within the .desktop file is

gnome-terminal --execute bash -c "http:www.example.com/location/of/bash/script.txt" ; bash

When I click the .desktop file it opens, tries to run the script and gives the error 'no such file or directory' any help on this is much appreciated.

6

Also simple and dangerous:

Make your desktop file look like this:

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Sample Application Name
Comment=A sample application
Exec=sh -c 'curl -s http://www.example.com/path/to/script.sh | bash'
Icon=application.png
Terminal=true

This will spawn a sub-shell, run 'curl' to read out the file, and then pipe it into bash.

  • I've had issues with a pipe in Exec lines before. They seem to not like pipes. I've only been able to use a pipe in a sub-shell when using .desktop files. – user323419 Dec 9 '15 at 18:59
  • You're right, I tested and it doesn't work that way. Probably Exec= is just meant to run a single command. – kos Dec 9 '15 at 19:23
0

I suggest you put together a script that does everything in 2 steps: download the original script , and then execute it locally.

Something like this :

#!/bin/bash

#download , save as /tmp/script
wget -O /tmp/script.sh www.example.com/location/of/bash/script.txt
#give executable permissions
chmod +x /tmp/script.sh
# run it
gnome-terminal --execute bash -c "/tmp/script.sh; bash"
  • The way you suggested above is a good solution, but I am looking for a one-file solution, almost like an installation wizard. For example, if I have a hello.sh that reads: echo 'Hello', and then have hello.sh located on the internet, is there a way I can have a single separate file named 'runhello' that one can download and then run locally to execute the hello.sh script via bash locally? So that one can execute the script without having to know anything about executing items in the terminal. – KrewTahn Dec 9 '15 at 15:43
  • I think you did that intentionally, but this leaves a interactive shell running on top of the script. – kos Dec 9 '15 at 19:00
  • @kos I guess I could use exec there to get around that shell – Sergiy Kolodyazhnyy Dec 9 '15 at 19:02
  • No I just thought that maybe it's more convenient to let the terminal close, otherwise you have to shut it down manually, but well maybe OP likes it more that way. :) – kos Dec 9 '15 at 19:24
0

Simple and dangerous. Dangerous? Yes, see below …

wget -q -O - http://www.example.com/location/of/bash/runhello | bash

or with

bash <(curl -s http://www.example.com/location/of/bash/runhello)

or another combination of wget/curl and bash.


Warning:

Perhaps it's a nice idea for your own scripts, but not for other people's:

Check the content of the script before executing and never run a script in the way bash <(curl -s URL) or wget -q -O - URL | bash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.