Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute bash script from URL

Tags:

linux

bash

curl

People also ask

How do I run a bash script from a website?

We can run a bash script using the HTML button in the browser using the shell_exec() or exec() or system() functions. The three functions will return the same value if we use these functions. The differences are: shell_exec() returns the complete output as a string.

How do I execute a bash script?

To invoke a bash function, simply use the function name. Commands between the curly braces are executed whenever the function is called in the shell script. The function definition must be placed before any calls to the function.


source <(curl -s http://mywebsite.com/myscript.txt)

ought to do it. Alternately, leave off the initial redirection on yours, which is redirecting standard input; bash takes a filename to execute just fine without redirection, and <(command) syntax provides a path.

bash <(curl -s http://mywebsite.com/myscript.txt)

It may be clearer if you look at the output of echo <(cat /dev/null)


This is the way to execute remote script with passing to it some arguments (arg1 arg2):

curl -s http://server/path/script.sh | bash /dev/stdin arg1 arg2

For bash, Bourne shell and fish:

curl -s http://server/path/script.sh | bash -s arg1 arg2

Flag "-s" makes shell read from stdin.


Using wget, which is usually part of default system installation:

bash <(wget -qO- http://mywebsite.com/myscript.txt)

Use:

curl -s -L URL_TO_SCRIPT_HERE | bash

For example:

curl -s -L http://bitly/10hA8iC | bash

Try just:

bash <(curl -s http://mywebsite.com/myscript.txt)