我正在編寫一個快速腳本,用於計算從/ proc/net/dev中提取的數據的單個接口吞吐量,並且出現問題。它將其從字節轉換爲兆字節。(standard_in)1:解析錯誤
這是在我的Ubuntu服務器(3.2.0內核)上工作,但是當我嘗試在舊設備(2.6.18時代)上運行它時,它無法工作。我不確定我做錯了什麼。
這裏是我的代碼片段:
int1_byte_rx=`cat $logfile | grep $int1 | awk '{print $2}' | awk '{sum+=$1} END {print sum}'`
int1_byte_tx=`cat $logfile | grep $int1 | awk '{print $10}' | awk '{sum+=$1} END {print sum}'`
int1_rx_thrpt=$(echo "($int1_byte_rx * 0.00000762939453)/$iterations/($time * 60)" | bc -l)
int1_tx_thrpt=$(echo "($int1_byte_tx * 0.00000762939453)/$iterations/($time * 60)" | bc -l)
當我運行此我得到以下錯誤(從調試模式):
int1_rx_thrpt=$(echo "($int1_byte_rx * 0.00000762939453)/$iterations/($time * 60)" | bc -l)
echo "($int1_byte_rx * 0.00000762939453)/$iterations/($time * 60)" | bc -l
++ echo '(1.13417e+10 * 0.00000762939453)/57/(5 * 60)'
++ bc -l
(standard_in) 1: parse error
(standard_in) 1: parse error
+ int1_rx_thrpt=
int1_tx_thrpt=$(echo "($int1_byte_tx * 0.00000762939453)/$iterations/($time * 60)" | bc -l)
echo "($int1_byte_tx * 0.00000762939453)/$iterations/($time * 60)" | bc -l
++ echo '(9.78048e+09 * 0.00000762939453)/57/(5 * 60)'
++ bc -l
(standard_in) 1: parse error
(standard_in) 1: parse error
我已經能夠追查問題回本身,但我不確定如何改正它。
歡迎任何建議。
感謝您的時間,
你可以更容易地用'echo 1.13417e + 10 | bc -l'。 (或者交互式運行'bc -l',只需輸入'1.13417e + 10'。) – sarnold
確實我可以 - 謝謝。從這個信息我可以假設它不喜歡科學記數法。有沒有一個特定的模式允許這個?我的印象是mathlib允許這樣做(它適用於bc版本1.06.95但不是1.06) – Numpty
也不是1.06.94。 –