Search code examples
bashubuntu-16.04execution

How to run (./) a bash script located in the cloud?


Using a ubuntu 16.04 what I do is :

  1. Download the .sh script using wget https://gist.githubusercontent.com/...
  2. Turn the .sh file executable sudo chmod guo+x sysInit.sh
  3. Execute the code through sudo ./sysInit.sh

I was wondering if it is possible to run the code directly from the web. Would be something like: sudo ./ https://gist.githubusercontent.com/....

Is it possible to do that?


Solution

  • You can use cUrl to download and run your script. I don't think its installed by default on Ubuntu so you'll have to sudo apt-get install curl first if you want to use it. To download and run your script with sudo just run

    curl -sL https://gist.githubusercontent.com/blah.sh | sudo sh
    

    Be warned this is very risky and not advised for security reasons. See this related question why-using-curl-sudo-sh-is-not-advised