[英]How to get Physical Memory from top -l1 using AWK in OS X Mavericks?
我在Mac上使用這個腳本用於GeekTools,下面的代碼適用於以前的OSX版本。 但是在Mavericks中,它會返回下面指定的錯誤。
$ top -l1 | grep "PhysMem"|awk '{print "X"int(($2+$4)/($8+$10)*50)"X"}'
awk: division by zero
input record number 1, file
source line number 1
awk之前的輸出:
$ top -l1 | grep "PhysMem"
PhysMem: 6796M used (936M wired), 1282M unused.
由於awk對我來說是一個未知的領域,有人可以發布快速解決方案嗎?
試試這些:
top -l 1 | awk '/PhysMem/ {print $4}' | sed s/M// | sed s/\(//
二手記憶:
top -l 1 | awk '/PhysMem/ {print $2}
空閑記憶:
top -l 1 | awk '/PhysMem/ {print $6}
通過刪除不需要的括號和int
清理解決方案
top -l1 | awk '/PhysMem/ {print int((1-$6/($2+$6))*50)}'
42
這實現了我正在尋找的結果。
top -l1 |awk '/PhysMem/ {print "X"int((1-(int($6)/((int($6)+int($2)))))*50)"X"}'
對於任何人的興趣和一些上下文,我試圖將這個CPU geeklet轉換為Memory geeklet: http ://freshmacapps.com/geektool-scripts/geektool-cpu-circle-monitor
非常感謝所有貢獻的人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.