Milano
Milano

Reputation: 18745

Executing remote script by curl doesn't work

I'm trying to run one script (which installs and setups Postgres DB) from another script (test.sh). The problem is that the script which is called inside my script is remote (online on GitHub) and it doesn't work.

I tried to call the script three different ways.

  1. locally - works
  2. remotely using bash <(curl... - raises error
  3. remotely using curl ... | bash -s - downloads script and hangs...

test.sh

#!/bin/bash

# this works correctly (it's the same but local)
sudo bash postgres/setup.sh 

# this raises "bash: /dev/fd/63: No such file or directory"
sudo bash <(curl -s https://raw.githubusercontent.com/milano-slesarik/sh-ubuntu-instant/master/postgres/setup.sh)

# this hangs
curl https://raw.githubusercontent.com/milano-slesarik/sh-ubuntu-instant/master/postgres/setup.sh | sudo bash -s

The last one probably downloads the script but then hangs...

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1532  100  1532    0     0   8281      0 --:--:-- --:--:-- --:--:--  8281

Do you know how to make it work? I want my scripts to be online so I don't have to clone/download then all the time.

Upvotes: 1

Views: 814

Answers (2)

Philippe
Philippe

Reputation: 26727

This may achieve what you wanted :

sudo bash -c "bash <(curl -s https://raw.githubusercontent.com/milano-slesarik/sh-ubuntu-instant/master/postgres/setup.sh)"

Upvotes: 0

mtnezm
mtnezm

Reputation: 1027

The reason why it hangs when you run curl -s $script |bash -s seems to be a misbehaviour in the script itself, at least as long as you run it like that. You can debug this by adding the -x flag to the bash command. Then you can see the following message spawning in an endless loop, due to the while statement contained in the script:

++ read -p 'Do you wan'\''t to install postgres? [y/n]: ' yn
++ case $yn in

Also, as long as you are running the script this way, to avoid this behaviour I would remove those lines in which the script is expecting some kind of user input. If that is not the case, the easiest way is just to download it via curl and then run it locally from your terminal.

Upvotes: 2

Related Questions