我正在嘗試創建一個 shell 腳本,它應該提示并讀取值作為輸入,然后在特定的行和列中使用該值更新相同的 shell 腳本。
或者,如果我可以使用另一個 shell 腳本來獲取值并更新原始檔案。
我想讀取并更新以下引數值作為輸入
USER=''user''
PASS=''password''
URL=''http://10.xxx.xxx.xxx:9206/MGR/status''
PORT1=''9204''
PORT2=''9206''
完整腳本
#!/bin/bash
USER=''user''
PASS=''password''
URL=''http://10.xxx.xxx.xxx:9206/MGR/status''
PORT1=''9204''
PORT2=''9206''
echo Metrics for $PORT1
echo =====================
maxthreads=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk '{ print $4 }'`
echo Max Threads: $maxthreads
currentthreadcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk '{ print $8 }'`
echo Current Threads: $currentthreadcount
busythreadcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk '{gsub("<br>", "");print $12}'`
echo Busy Threads: $busythreadcount
maxprocesstime=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk '{ print $16 }'`
echo Max Processing Time: $maxprocesstime
processtime=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk '{ print $20 }'`
echo Processing Time: $processtime
requestcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk '{ print $24 }'`
echo Request Count: $requestcount
errorcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk '{ print $27 }'`
echo Error Count: $errorcount
echo Metrics for $PORT2
echo =====================
maxthreads=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk '{ print $4 }'`
echo Max Threads: $maxthreads
currentthreadcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk '{ print $8 }'`
echo Current Threads: $currentthreadcount
busythreadcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk '{gsub("<br>", "");print $12}'`
echo Busy Threads: $busythreadcount
maxprocesstime=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk '{ print $16 }'`
echo Max Processing Time: $maxprocesstime
processtime=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk '{ print $20 }'`
echo Processing Time: $processtime
requestcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk '{ print $24 }'`
echo Request Count: $requestcount
errorcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk '{ print $27 }'`
echo Error Count: $errorcount
我的意圖不是編輯檔案和輸入值,而是將其作為提示讀取并在后臺更新檔案。
uj5u.com熱心網友回復:
感謝團隊。我使用 AWS 秘密管理器做了另一種方法來實作這一點。該代碼可以從秘密管理器中讀取資料。所以我們的工程師可以在密鑰管理器中更新相同的鍵值對。謝謝大家的建議和幫助。我將進一步研究建議改進代碼的選項。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/418628.html
標籤:
