shell脚本中的多个curl命令



我在shell脚本test.sh中有以下代码和3个curl命令。

curl -o C:Usersuser1folder1folder2folder3folder425Oct2021.gz "https://abc.xyz.aaa.com/v3/test-logs/download?userID=AA4d3DFF&fileName=25Oct2021.gz" --header "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxx"
curl -o C:Usersuser1folder1folder2folder3folder424Oct2021.gz "https://abc.xyz.aaa.com/v3/test-logs/download?userID=AA4d3DFF&fileName=24Oct2021.gz" --header "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxx"
curl -o C:Usersuser1folder1folder2folder3folder423Oct2021.gz "https://abc.xyz.aaa.com/v3/test-logs/download?userID=AA4d3DFF&fileName=23Oct2021.gz" --header "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxx"

我使用的是Windows 10机器,当我尝试使用sh test.sh在命令提示符下执行shell脚本时,文件没有按预期下载。如果我使用单独的curl命令并在命令提示符下执行它们,它们会工作得非常好。我试着调整shell脚本并删除" "运行这个。还有什么我可以做的吗?

我编辑了Shell脚本,只运行其中一个curl命令,结果如下:

以下是作为sh test.sh

运行shell脚本的输出
>sh test1.sh
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100    29    0    29    0     0     29      0 --:--:-- --:--:-- --:--:--    56

这是其中一个curl命令的输出:

curl -o C:Usersuser1folder1folder2folder4folder425Oct2021.gz "https://abc.xyz.aaa.com/v3/test-logs/download?userID=AA4d3DFF&fileName=25Oct2021.gz" --header "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxx"
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100 4035k    0 4035k    0     0   672k      0 --:--:--  0:00:06 --:--:--  838k

更新:在脚本test.sh

中使用curl -v运行会得到以下curl命令的输出
sh test1.sh
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 11.111.111.111...
* TCP_NODELAY set
* Connected to abc.xyz.aaa (11.111.111.111) port 443 (#0)
* schannel: SSL/TLS connection with abc.xyz.aaa port 443 (step 1/3)
* schannel: checking server certificate revocation
* schannel: sending initial handshake data: sending 184 bytes...
* schannel: sent initial handshake data: sent 184 bytes
* schannel: SSL/TLS connection with abc.xyz.aaa port 443 (step 2/3)
* schannel: failed to receive handshake, need more data
* schannel: SSL/TLS connection with abc.xyz.aaa port 443 (step 2/3)
* schannel: encrypted data got 3026
* schannel: encrypted data buffer: offset 3026 length 4096
* schannel: sending next handshake data: sending 93 bytes...
* schannel: SSL/TLS connection with abc.xyz.aaa port 443 (step 2/3)
* schannel: encrypted data got 258
* schannel: encrypted data buffer: offset 258 length 4096
* schannel: SSL/TLS handshake complete
* schannel: SSL/TLS connection with abc.xyz.aaa port 443 (step 3/3)
* schannel: stored credential handle in session cache
> GET /v3/test-logs/download?UserId=AA4d3DFF&fileName=25Oct2021.gz HTTP/1.1
> Host: abc.xyz.aaa
> User-Agent: curl/7.55.1
> Accept: */*
> Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
* schannel: client wants to read 102400 bytes
* schannel: encdata_buffer resized 103424
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: encrypted data got 303
* schannel: encrypted data buffer: offset 303 length 103424
* schannel: decrypted data length: 274
* schannel: decrypted data added: 274
* schannel: decrypted data cached: offset 274 length 102400
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: decrypted data buffer: offset 274 length 102400
* schannel: schannel_recv cleanup
* schannel: decrypted data returned 274
* schannel: decrypted data buffer: offset 0 length 102400
< HTTP/1.1 403 Forbidden
< Server: acvf
< Date: Mon, 25 Oct 2021 18:53:02 GMT
< Content-Type: application/json
< Transfer-Encoding: chunked
< Connection: keep-alive
< Cache-Control: private, must-revalidate
< pragma: no-cache
< expires: -1
<
{ [40 bytes data]
100    29    0    29    0     0     29      0 --:--:-- --:--:-- --:--:--    50
* Connection #0 to host abc.xyz.aaa left intact

在(ba)sh中是转义字符,但在Windows命令提示符中不是,这解释了执行中的差异。

您需要双反斜杠(\),将每个包含反斜杠的字符串括在单引号内('),或将所有反斜杠替换为正斜杠(/)。

相关内容

  • 没有找到相关文章

最新更新