使用 bash curl wget 一键脚本 报错Error 没反应 怎么办 Troubleshooting

我们这种小白只会用一键脚本,经常是这样的使用形式:

bash <(curl -好多参数 脚本的地址)

如果顺利当然最好,如果遇到问题,希望本文能帮到你。

参考资料

https://www.ruanyifeng.com/blog/2019/09/curl-reference.html
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Redirections

-bash: curl: command not found

-bash: curl: command not found

说明 curl 命令没有安装

安装的命令如下:

#Debian or Ubuntu
apt install -y curl
#CentOS
yum -y install curl

如果安装报错, 一般是你软件源没有更新

更新的命令如下:

#Debian or Ubuntu
apt update
#CentOS
yum update

如果你的系统是Debian10, 有可能在apt udpate时遇到问题

你需要更改软件源:

apt-get --allow-releaseinfo-change update
apt-get dist-upgrade

什么信息都没有, 没有报错

看起来就像没有执行一样。

1. 一般来说, 使用了 -s 参数

你可以确认一下

2. 作者刻意为之

有些作者喜欢简洁,或者是在特殊环境下,刻意想要这样的效果。你可以向作者求证是否是正常的结果。

3. 去掉 -s 参数

去掉 -s 参数不影响脚本本身的功能. 实际上, 在你认为遇到问题需要调试时, 建议你只保留 -L 参数重新执行一键脚本命令. 这样可以获得更多的细节信息用以定位问题.

error setting certificate verify locations

例如:

curl: (77) error setting certificate verify locations:  CAfile: /etc/ssl/certs/ca-certificates.crt CApath: /etc/ssl/certs

curl: (77) error setting certificate verify locations:  CAfile: /etc/ssl/certs/ca-certificates.crt CApath: /etc/ssl/certs

1. 添加 -k 参数 跳过 SSL 证书的验证

bash <(curl -kL 脚本的地址)
bash <(curl -kL 脚本的地址)

2. 安全性分析

对于我们一键脚本搭梯子来说, 我们执行的VPS在境外, 我们拉取的脚本一般是在GitHub, 有人能针对性地在VPS与GitHub之间的这个连接发起攻击吗? 很难.

即使有人发起了攻击, 让你获取了一个有后门的脚本搭梯子, 那么攻击者有能力拦截, 复制, 篡改你的流量数据. 如果你保持一个良好的上网冲浪习惯, 所有的流量都是https协议, 用SSL加密过的, 而且CA证书也没有漏洞, 那么, 攻击者最多可以获得你浏览网站的域名的记录, 无法拿到你的数据本身(比如, 用户名, 密码等), 也无法伪造你的身份进行操作(比如, 银行转账等)

反过来说, 如果你在一个比较危险的网络环境下使用 curl 获取信息, 或者你要搭建的服务比较重要, 请进行风险评估后再使用 -k 参数.

-L 参数是什么意思

-L 参数会让 HTTP 请求跟随服务器的重定向

重定向是什么意思?

URL 重定向,也称为 URL 转发,HTTP 重定向(HTTP redirects)。简单一点解释就是,服务器告诉浏览器,你要的东西不在这个URL,请去另一个URL获得。
这个重定向的过程是可以链状多次发生的。URL A - URL B - URL C - ... - 真正存放文件的URL
比如, 你在浏览器的地址栏中输入 
https://git.io/xkcdpw
最终打开的是
https://crazypeace.github.io/xkcd-password-generator/
xkcd密码生成器 password generator

-L 参数就是要自动进行这个跳转的过程

用 -i 参数可以查看这个跳转的返回信息

curl -i https://git.io/xkcdpw
curl -i 返回302

用 -iL 参数可以看到整个跳转的全过程

curl -iL git.io/ccaasudo.sh
整个返回结果较长,我放在文末。

bash <( 中间shell命令 ) 是什么意思

意思是把中间shell命令的返回(输出)灌到bash中去执行。如果中间shell命令是curl获取一个脚本的内容,那么整个命令就是把这个脚本的内容灌到bash中执行。简单一点解释就是,把脚本的内容一行一行敲到命令行中执行。

这不就是一键脚本要做的事情嘛。


netstat: command not found

这个时候用 apt install -y netstat 会报错 E: Unable to locate package netstat 说没有这个安装包。

我们上google搜一下"Unable to locate package netstat",就能找到解决方案,原来是要安装 net-tools

apt install -y net-tools


==================

wget 可能遇到 SSL 证书的问题

使用 --no-check-certificate 参数跳过验证. 安全性方面的分析与 curl -k 一样. 如,

bash <(wget -qO- --no-check-certificate https://git.io/v2ray.sh)


wget 可能遇到gzip压缩问题

命令行报错胡言乱语. 单独 wget 取资源, 得到的是乱码. 

使用 --compression=auto 参数, 如

bash <(wget -qO- --compression=auto https://ghproxy.crazypeace.repl.co/https://git.io/v2ray.sh)



==================


==================
附 -iL 参数的一次调用过程
root@391932510woiden:~#  curl -iL git.io/ccaasudo.sh
HTTP/1.1 301 Moved Permanently
Content-Length: 0
Location: https://git.io/ccaasudo.sh

 

HTTP/2 302 
content-type: text/html;charset=utf-8
location: https://github.com/crazypeace/ccaa/raw/master/ccaa.sh
content-length: 0
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-runtime: 0.003515
x-node: gitio-5fcb757d96-rbdpt
x-revision: c3d8f37e8e0ab0221c670bfb063e5e966c213052
strict-transport-security: max-age=63072000; includeSubDomains; preload
server: WEBrick/1.4.4 (Ruby/2.6.9/2021-11-24)
date: Thu, 12 May 2022 18:15:06 GMT
x-github-backend: Kubernetes
x-github-request-id: AF74:151D:AC965:63AA5D:627D4EAA

 

HTTP/2 302 
server: GitHub.com
date: Thu, 12 May 2022 18:14:16 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Accept-Encoding, Accept, X-Requested-With
permissions-policy: interest-cohort=()
access-control-allow-origin: https://render.githubusercontent.com
location: https://raw.githubusercontent.com/crazypeace/ccaa/master/ccaa.sh
cache-control: no-cache
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
expect-ct: max-age=2592000, report-uri="https://api.github.com/_private/browser/errors"
content-security-policy: default-src 'none'; base-uri 'self'; block-all-mixed-content; child-src github.com/assets-cdn/worker/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com objects-origin.githubusercontent.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com cdn.optimizely.com logx.optimizely.com/v1/events translator.github.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com online.visualstudio.com/api/v1/locations github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src render.githubusercontent.com viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: github.githubassets.com identicons.github.com github-cloud.s3.amazonaws.com secured-user-images.githubusercontent.com/ *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; worker-src github.com/assets-cdn/worker/ gist.github.com/assets-cdn/worker/
content-length: 0
x-github-request-id: E650:EBDF:21BA6A9:2375AB6:627D4EAA

 

HTTP/2 200 
cache-control: max-age=300
content-security-policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
content-type: text/plain; charset=utf-8
etag: "3f42d6e53546c753463238fcf1752736a8e03a6172a7ce7f1bf77a4625d258f8"
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
x-frame-options: deny
x-xss-protection: 1; mode=block
x-github-request-id: 7730:1145C:21BF60:241BF7:627D4CA5
accept-ranges: bytes
date: Thu, 12 May 2022 18:15:06 GMT
via: 1.1 varnish
x-served-by: cache-fra19165-FRA
x-cache: HIT
x-cache-hits: 1
x-timer: S1652379307.946338,VS0,VE1
vary: Authorization,Accept-Encoding,Origin
access-control-allow-origin: *
x-fastly-request-id: d56440e61e8685bab9dc59ce372f43acfad322b1
expires: Thu, 12 May 2022 18:20:06 GMT
source-age: 50
content-length: 9011

#!/bin/bash
##### 一键安装File Browser + Aria2 + AriaNg #####
##### 作者:xiaoz.me 更新时间:2020-02-27 #####
#############################################################
#####   remove cdn option                               #####
#####   support IPv4 or IPv6                            #####
#####   add default_secret                              #####
#####   crazypeace @ 2022-05-12                         #####
############################################################# 

脚本的实际内容太长,以下省略。 

评论

The Hot3 in Last 30 Days

无服务器 自建短链服务 Url-Shorten-Worker 完整的部署教程

ClouDNS .asia免费域名 托管到CloudFlare开CDN白嫖Websocket WS通道翻墙 / desec.io