我想捕獲幾個遠程設備的輸出使用cli命令,然後grep 717GE和打印屏幕爲多個主機。正如你在下面看到的,它從$ hosts獲取IP並將它傳遞給$ outip,而不是從命令行使用相同命令時顯示的內容。我認爲這個變量會捕獲從給定命令返回的數據。有人能幫助我並幫助我理解我在做什麼錯嗎?我對學習真的很感興趣,所以請暫緩這些拙劣的評論。如果可能的話。bash從遠程機器捕獲輸出到一個變量
for host in ${hosts[@]}; do
seven=($(cli $hosts show gpon ont summary -n --max=3 --host))
outip=($(grep 717GE $seven))
echo $outip
done
輸出:
+ for host in '${hosts[@]}'
+ seven=($(cli $hosts show gpon ont summary -n --max=3 --host))
++ cli 10.100.112.2 show gpon ont summary -n --max=3 --host
+ outip=($(grep 717GE $seven))
++ grep 717GE 10.100.112.2 grep: 10.100.112.2: No such file or directory
你的命令不似乎很有意義。嘗試'VAR = $(ssh user @ server「some command here」)' – devnull
ssh沒有在遠程設備上偵聽。我出於各種原因使用cli。用法:cli [] [c:] [選項] –
cvjones360
1.刪除括號'seven'和'outip':'seven = $(cli $ hosts show gpon ont summary -n --max = 3 --host)''outip = $(grep 717GE $ 7)'2.當設置'seven'時,你似乎有一個錯字:使用'$ host'而不是'$ hosts'。 – devnull