Execute bash script from URL
source <(curl -s http://mywebsite.example/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.example/myscript.txt)
It may be clearer if you look at the output of echo <(cat /dev/null)
execute script on remote using curl
You can not run a command/script via ftp (at least not that I've ever seen). If you have a web server on the same box or you use curl to call the script via http(s) or you can write a script that ssh's into the box and executes the command, see Ssh and run command upon connection in another question for help.
Run remote Python script via curl
Arguments come after the script name. To use standard input as the script, use -
as the name:
curl 45.55.88.55/script.py | python - --ip=172.19.242.32 --mac=102030405060
This is a pretty standard Unix argument convention, although not all programs obey it (mostly older programs).
Run bash script from GitHub with curl
The "Firstly" is more complex, but you might try a temporary shell script without using pipe.
curl -s https://raw.githubusercontent.com/roysubs/custom_bash/master/custom_loader.sh >tmp.sh
bash tmp.sh
Your "Secondly" question is very easy to explain, when you do curl -s https://git.io/Jt0fZ
, we get a Redirect 302, here is hints:
We try to get headers only from the server:
curl --head https://git.io/Jt0fZ
HTTP/1.1 302 Found
Server: Cowboy
Connection: keep-alive
Date: Sun, 25 Apr 2021 14:24:43 GMT
Status: 302 Found
Content-Type: text/html;charset=utf-8
Location: https://raw.githubusercontent.com/roysubs/custom_bash/master/custom_loader.sh
Content-Length: 0
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Runtime: 0.003242
X-Node: 69d60833-56c5-4364-94c1-6f0c5b12863f
X-Revision: 392798d237fc1aa5cd55cada10d2945773e741a8
Strict-Transport-Security: max-age=31536000; includeSubDomains
Via: 1.1 vegur
We see HTTP/1.1 302 Found
and Location: https://raw.githubusercontent.com/roysubs/custom_bash/master/custom_loader.sh
, not the real content of the latter.
So bash gets empty script to run, by default, curl does not do a second call to the new location, as does graphic webbrowsers usually do.
But you can do this to overcome the default:
curl -L https://git.io/Jt0fZ | bash
man curl gives this:
-L, --location
(HTTP) If the server reports that the requested page has moved to a different location (indicated with
a Location: header and a 3XX response code), this option will make curl redo the request on the new
place.
Use CURL Command to download remote files in Shell scripting
Using a valid url in my tests seemed to have no issues with this curl request. I also tried using with and without wrapping the url in a string like you are along with using brackets.
url="https://cdn.sstatic.net/Sites/stackoverflow/img/sprites.svg?v=1b3cdae197be"
# all work fine
curl -O -J $url
curl -O -J "$url"
curl -O -J "{$url}"
My best answer is that your $url_final variable is undefined, empty, or malformed.
How to keep a bash script open with wget or curl while executing and piping it to bash
Try, with curl
,
curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/matriarx/typescript/main/bin/init | sh
Related Topics
Why I Am Not Getting Signal Sigkill on Kill -9 Command in Bash
How to Get Errno When Epoll_Wait Returns Epollerr
How to You Configure The Command Prompt in Linux to Show Current Directory
Checking If a Binary Compiled with "-Static"
Graphics Card Memory and Virtual Address Space of a Process
Difference Between Arm-None-Eabi and Arm-Linux-Gnueabi
Where to Put Svn Repository Directory in Linux
Linux Append Console Output to a Logfile
How to Generate a Static HTML File from a Swagger Documentation
Linux Service Can't Load Library Path in The /Etc/Ld.So.Conf.D
Command to Check Status of Message Queue and Shared Memory in Linux