作者 主題: declare -i的問題  (閱讀 1858 次)

0 會員 與 1 訪客 正在閱讀本文。

cisco3662

  • 鑽研的研究生
  • *****
  • 文章數: 739
    • 檢視個人資料
declare -i的問題
« 於: 2011-02-11 12:21 »
請問各位,我於linux內進行snmpwalk的流量偵測,並將偵測到的值寫入檔案,我發現只要偵測到的值超過9位數(也就是10億),其存入檔案內的值會變成負數,我發現只要定義了declare -i就會有這樣的問題,懇請賜教,謝謝
代碼: [選擇]
       declare -i first_down=`snmpwalk 127.0.0.1 -c public .1.3.6.1.2.1.2.2.1.10.2|cut -d ":" -f 2`
        echo $first_down > /control/caldown
       declare -i first_up=`snmpwalk 127.0.0.1 -c public .1.3.6.1.2.1.2.2.1.16.2|cut -d ":" -f 2`
        echo $first_up > /control/calup


代碼: [選擇]
[root@localhost control]# first_up=`snmpwalk 127.0.0.1 -c public .1.3.6.1.2.1.2.2.1.16.2|cut -d ":" -f 2`
[root@localhost control]# echo $first_up
3216266446
[root@localhost control]# declare -i first_up=`snmpwalk 127.0.0.1 -c public .1.3.6.1.2.1.2.2.1.16.2|cut -d ":" -f 2`
[root@localhost control]# echo $first_up
-1078696146
[root@localhost control]# unset first_up
[root@localhost control]# first_up=`snmpwalk 127.0.0.1 -c public .1.3.6.1.2.1.2.2.1.16.2|cut -d ":" -f 2`
[root@localhost control]# echo $first_up
3216279150
« 上次編輯: 2011-02-11 13:02 由 cisco3662 »