当我运行这个命令时,它工作得很好:
# curl https://google.com产出:
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>但是,当我在shell脚本.sh文件中执行相同的操作时:
#!/bin/bash
curl https://google.com产出:
curl: (6) Could not resolve host: google.com; Unknown errorgrep curl /home/pmm/deploy-vsf/test_bot.sh | od -c的输出:
[root@host ~]# grep curl /home/pmm/deploy-vsf/test_bot.sh | od -c
0000000 c u r l h t t p s : / / g o
0000020 o g l e . c o m \n
0000031注意:脚本正在以su的形式运行,但是脚本驻留在pmm用户的家中
发布于 2022-11-11 18:03:29
您的交互式shell 正在使用别名用于curl,它告诉它使用特定的web代理:
type curl
curl is aliased to `curl -x 192.168.188.170:3128'运行脚本时,不包括别名(它们主要用于交互使用),因此您需要自己指定缺少的部分。
#!/bin/bash
curl -x 192.168.188.170:3128 https://google.com更好的解决方案可能是设置环境变量http_proxy而不是混叠curl。这将适用于几乎所有的web工具(但也不能跨su或sudo使用,除非目标用户也定义它):
export http_proxy=192.168.188.170:3128https://unix.stackexchange.com/questions/724496
复制相似问题