繁体   English   中英

通过 curl 执行远程脚本不起作用

[英]Executing remote script by curl doesn't work

我正在尝试从另一个脚本( test.sh )运行一个脚本(安装和设置 Postgres DB)。 问题是在我的脚本中调用的脚本是远程的(在 GitHub 上在线)并且它不起作用。

我试图以三种不同的方式调用脚本。

  1. 本地工作
  2. 远程使用bash <(curl... - 引发错误
  3. 远程使用curl... | bash -s curl... | bash -s - 下载脚本并挂起...

测试.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

最后一个可能会下载脚本但随后挂起......

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

你知道如何让它工作吗? 我希望我的脚本在线,这样我就不必一直克隆/下载。

运行curl -s $script |bash -s时它挂起的原因似乎是脚本本身的不当行为,至少只要你这样运行它。 您可以通过将-x标志添加到bash命令来调试它。 然后,由于脚本中包含while语句,您可以看到以下消息在无限循环中生成:

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

此外,只要您以这种方式运行脚本,为了避免这种行为,我会删除脚本期望某种用户输入的那些行。 如果不是这种情况,最简单的方法就是通过curl下载它,然后从终端本地运行它。

这可能会达到你想要的:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM