我想从https://github.com/sschwartzman/newrelic-unix-plugin下载二进制文件.但是url会重定向到另一个地址,所以我使用awk来解析它.例如
curl -I https://github.com/sschwartzman/newrelic-unix-plugin/blob/master/dist/newrelic_unix_plugin.tar.gz\?raw\=true | awk '/Location:/ {print $2}'
Run Code Online (Sandbox Code Playgroud)
结果如我所料,例如
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
https://github.com/sschwartzman/newrelic-unix-plugin/raw/master/dist/newrelic_unix_plugin.tar.gz
Run Code Online (Sandbox Code Playgroud)
解析实际地址.所以我只想用curl下载它.但我总是失败.我的操作系统是osx El Capitan(我没有wget).
curl -I https://github.com/sschwartzman/newrelic-unix-plugin/blob/master/dist/newrelic_unix_plugin.tar.gz\?raw\=true | awk '/Location:/ {curl -O $2}'
Run Code Online (Sandbox Code Playgroud)
ps我试图直接通过curl下载二进制文件,但仍然失败了.下载的文件大小和内容不正确.
curl -O https://github.com/sschwartzman/newrelic-unix-plugin/raw/master/dist/newrelic_unix_plugin.tar.gz
Run Code Online (Sandbox Code Playgroud)
curl有-L可以处理重定向的开关.
所以,这应该工作:
curl -L https://github.com/sschwartzman/newrelic-unix-plugin/blob/master/dist/newrelic_unix_plugin.tar.gz\?raw\=true -o newrelic_unix_plugin.tar.gz
Run Code Online (Sandbox Code Playgroud)