次のコードのメモリ値に対してパーセント丸めをどのように実行できますか?

次のコードのメモリ値に対してパーセント丸めをどのように実行できますか?

ホスト名=$(ssh ${i}ホスト名-s)を実行する

    memory=$(ssh ${i} free -t | awk 'FNR == 2 {printf(" %.2f%"), $3/$2*100}')
    mem_health=$(ssh ${i} free -t | awk 'FNR == 2 {printf(" %.2f%"), $3/$2*100}')
    if [ ${mem_health} -ge 80 ];
    then
            mem_health="CRITICAL"
    else
            mem_health="NORMAL"
    fi

ベストアンサー1

使用

mem_health=$(ssh ${i} free -t | awk 'FNR == 2 {printf(" %d"), $3/$2*100}')

つまり、整数が必要で、mem_health 変数にパーセント記号が必要ないので、%d代わりに使用します。%.2f%

おすすめ記事