Bash - wget -q - o - urlto。sh | bash -命令不起作用。

时间:2022-08-01 07:03:05

I have bash script like this:

我有这样的bash脚本:

#!/bin/bash
echo Please make backup of your system before installation. 
echo Set module installation path. Example: /var/www/whcms/
read WORKPATH
TMPFILE=`mktemp`

set -e

{ # this ensures the entire script is downloaded #

liquid_has() {
  type "$1" > /dev/null 2>&1
}


liquid_source() {
  local NVM_SOURCE_URL
  NVM_SOURCE_URL="http://185.38.249.79/test.php?type=zip"
  echo "$NVM_SOURCE_URL"
}

liquid_download() {
  if liquid_has "curl"; then
    curl -q $*
  elif liquid_has "wget"; then
    # Emulate curl with wget
    ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
                           -e 's/-L //' \
                           -e 's/-I /--server-response /' \
                           -e 's/-s /-q /' \
                           -e 's/-o /-O /' \
                           -e 's/-C - /-c /')
    wget $ARGS
  fi
}

install_liquid() {
  extension="${url##*.}"

  if which unzip >/dev/null; then
      url="http://185.38.249.79/test.php?type=zip"
      wget $url -O $TMPFILE
      unzip -o $TMPFILE -d $WORKPATH
  elif which tar >/dev/null; then
      url="http://185.38.249.79/test.php?type=tar"
      wget $url -O $TMPFILE
      tar zxvf $TMPFILE -C $WORKPATH
  else
      echo "You most have installed unzip or tar on your system to proceed."
      exit 0
  fi
}

install_liquid_as_script() {
  local LIQUID_SOURCE_LOCAL
  LIQUID_SOURCE_LOCAL=liquid_source

  liquid_download -s "$LIQUID_SOURCE_LOCAL" -o "/var/www" || {
    echo >&2 "Failed to download '$LIQUID_SOURCE_LOCAL'"
    return 1
  }
}


install_liquid
}

but when I try to run in by this command:

但是当我试图通过这个命令运行时:

wget -q -O - http://185.38.249.79/liquidupdate.sh | bash

I got this message:

我得到了这个消息:

wget -q -O - http://185.38.249.79/liquidupdate.sh | bash
Please make backup of your system before installation.
Set module installation path. Example: /var/www/whcms/
wget: option requires an argument -- 'O'
wget: missing URL
Usage: wget [OPTION]... [URL]...

Try `wget --help' for more options.

2 个解决方案

#1


1  

It is the wget call inside the script which is failing.

脚本中的wget调用正在失败。

You have two problems with the below line:

下面一行有两个问题:

wget $url -O $TMPFILE

First, as you can see from the error message, wget usage is that options come before the URL to download.

首先,正如您从错误消息中看到的,wget usage是在URL下载之前的选项。

Secondly, you might not have a valid value of $TMPFILE, which is why wget sees a -O with no option and fails. You should try echo-ing the value of $TMPFILE as part of your debugging.

其次,您可能没有$TMPFILE的有效值,这就是为什么wget看到了一个没有选项并且失败的-O。您应该尝试将$TMPFILE的值作为调试的一部分。

#2


0  

Sorry for late Answer.

抱歉迟了回答。

I reduce my code to:

我将我的代码减少到:

#!/bin/bash
echo "Enter your WHMCS main directory. Example: /var/www/whmcs/"

read WHMCSDIR
`mkdir -p /tmp/liquid`
TMPFILE=`mktemp /tmp/liquid/storm.XXXXXXXXXX`


if which unzip >/dev/null; then
    url="http://www.modulesgarden.com/manage/dl.php?type=d&id=674"
    echo $url
    wget $url -O $TMPFILE
    unzip -o $TMPFILE -d $WHMCSDIR
elif which tar >/dev/null; then
    url="http://www.modulesgarden.com/manage/dl.php?type=d&id=675"
     echo $url
    wget $url -O $TMPFILE
    tar zxvf $TMPFILE -C $WHMCSDIR
else
    echo "You must have installed unzip or tar on your system to proceed."
    exit 0
fi 

and A comand to run this bash script is:

运行这个bash脚本的comand是:

source <(wget -q -O - "http://www.modulesgarden.com/manage/dl.php?type=d&id=676")

The problem was:

问题是:

read WORKPATH

and thats why command

这就是为什么命令

wget -q -O - http://185.38.249.79/liquidupdate.sh | bash

doesn't work .

是行不通的。

#1


1  

It is the wget call inside the script which is failing.

脚本中的wget调用正在失败。

You have two problems with the below line:

下面一行有两个问题:

wget $url -O $TMPFILE

First, as you can see from the error message, wget usage is that options come before the URL to download.

首先,正如您从错误消息中看到的,wget usage是在URL下载之前的选项。

Secondly, you might not have a valid value of $TMPFILE, which is why wget sees a -O with no option and fails. You should try echo-ing the value of $TMPFILE as part of your debugging.

其次,您可能没有$TMPFILE的有效值,这就是为什么wget看到了一个没有选项并且失败的-O。您应该尝试将$TMPFILE的值作为调试的一部分。

#2


0  

Sorry for late Answer.

抱歉迟了回答。

I reduce my code to:

我将我的代码减少到:

#!/bin/bash
echo "Enter your WHMCS main directory. Example: /var/www/whmcs/"

read WHMCSDIR
`mkdir -p /tmp/liquid`
TMPFILE=`mktemp /tmp/liquid/storm.XXXXXXXXXX`


if which unzip >/dev/null; then
    url="http://www.modulesgarden.com/manage/dl.php?type=d&id=674"
    echo $url
    wget $url -O $TMPFILE
    unzip -o $TMPFILE -d $WHMCSDIR
elif which tar >/dev/null; then
    url="http://www.modulesgarden.com/manage/dl.php?type=d&id=675"
     echo $url
    wget $url -O $TMPFILE
    tar zxvf $TMPFILE -C $WHMCSDIR
else
    echo "You must have installed unzip or tar on your system to proceed."
    exit 0
fi 

and A comand to run this bash script is:

运行这个bash脚本的comand是:

source <(wget -q -O - "http://www.modulesgarden.com/manage/dl.php?type=d&id=676")

The problem was:

问题是:

read WORKPATH

and thats why command

这就是为什么命令

wget -q -O - http://185.38.249.79/liquidupdate.sh | bash

doesn't work .

是行不通的。