我正在使用腳本來獲取最新版本的 Prometheus。我能夠做到這一點:
v=$(curl -v --silent https://github.com/prometheus/node_exporter/releases/latest 2>&1 | grep "tag" | cut -d "v" -f2)
echo "latest version is $v"
latest version is 1.3.1
但在下一步使用“wget”下載并使用變數:
wget https://github.com/prometheus/node_exporter/releases/download/v$v/node_exporter-$v.linux-amd64.tar.gz
它失敗:
https://github.com/prometheus/node_exporter/releases/download/v1.3.1
/node_exporter-1.3.1
.linux-amd64.tar.gz
我嘗試將 wget 與 '' 一起使用,或者將 {} 用于像 {$v} 這樣的變數,但我得到了相同的結果。有人能幫我嗎?
uj5u.com熱心網友回復:
添加| tr -d '\r'到您的 curl 命令以去除回車符,如下所示:
#!/bin/bash
v=$(curl -v --silent https://github.com/prometheus/node_exporter/releases/latest 2>&1 | grep "tag" | cut -d "v" -f2 | tr -d '\r')
echo "latest version is $v"
wget https://github.com/prometheus/node_exporter/releases/download/v$v/node_exporter-$v.linux-amd64.tar.gz
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/506944.html
