问题:
shell脚本中使用curl请求文件,发现 url太长后,会出现多个参数被分段处理,然后下载文件就失败了!
代码语言:javascript复制root@unode:/home/unode# curl -o test.mp3 http://192.168.21.112:9100/genewnms/20230610/abc_20230610183555108.mp3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X
-Amz-Credential=minioadmin/20230629/us-east-1/s3/aws4_request&X-Amz-Date=20230629T072812Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Sig
nature=451030f0c5326bf2ff81be366d3fb6f18fc75238cc9c394a2e6517300cc45710
ash: X-Amz-Signature=451030f0c5326bf2ff81be366d3fb6f18fc75238cc9c394a2e6517300cc45710: not found
root@unode:/home/unode# ash: X-Amz-Expires=86400: not found
ash: X-Amz-SignedHeaders=host: not found
ash: X-Amz-Date=20230629T072812Z: not found
& 会被系统解析为特殊符号、加转义符
root@unode:/home/unode# curl -o test.mp3 http://192.168.21.112:9100/genewnms/20230610/abc_20230610183555108.mp3?X-Amz-Algorithm=AWS4-HMAC-SHA256&
X-Amz-Credential=minioadmin/20230629/us-east-1/s3/aws4_request&X-Amz-Date=20230629T072812Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Am
z-Signature=451030f0c5326bf2ff81be366d3fb6f18fc75238cc9c394a2e6517300cc45710
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6568k 100 6568k 0 0 9755k 0 --:--:-- --:--:-- --:--:-- 9773k
root@unode:/home/unode#
加单引号
root@unode:/home/unode# curl -o test.mp3 'http://192.168.21.112:9100/genewnms/20230610/abc_20230610183555108.mp3?X-Amz-Algorithm=AWS4-HMAC-SHA256&
X-Amz-Credential=minioadmin/20230629/us-east-1/s3/aws4_request&X-Amz-Date=20230629T072812Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Si
gnature=451030f0c5326bf2ff81be366d3fb6f18fc75238cc9c394a2e6517300cc45710'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6568k 100 6568k 0 0 9594k 0 --:--:-- --:--:-- --:--:-- 9616k
root@unode:/home/unode#
1、& 会被系统解析为特殊符号,所以给路径的&号添加转义符
2、在url连接上加上双引号,将&进行转义;
3、curl 换成wget
代码语言:javascript复制
#curl 下载到临时文件
#curl -o ${TARGET_UPGRADE_FILE} "${new_upgrade_file_url}"
wget -O ${TARGET_UPGRADE_FILE} "${upgrade_file_url}"