1

Get system information for Mac OS X

Posted by admin on April 30, 2010 in Apple, Shell |

如需转载,请注明出处!
WebSite: http://www.jjos.org/
作者: 姜江 linuxemacs@gmail.com
QQ: 457283

该脚本获取cpu,进程,物理内存,虚拟内存和网络信息。可以给GeekTools使用。
下图是将以下代码通过GeekTools显示在桌面上的效果

代码


#!/opt/local/bin/gawk -f
###################################################################
# The author of this script is Jiang Jiang
# Copyright (C) 2010 by www.jjos.org
#
# Permission to use, copy, modify, and distribute this script for
# any purpose without fee this hereby granted, provided that this
# entire notice is included in all copies of any software which is
# or includes a copy or modification of this script and in all
# copies of the supporting documentation for such software.
###################################################################

BEGIN {
GetTopInfo()
}

END {
ShowCPUInfo()
ShowProcessInfo()
ShowPhysMemInfo()
ShowVMemInfo()
ShowNetworkInfo()
}

function GetTopInfo() {
CMDLINE="top -l 1"
while (CMDLINE |& getline) {
gsub(/,/, "", $0);
split($0, results)
if ($0 ~ /^Processes:/) {
PROCESS_TOTAL=results[2]
PROCESS_RUNNING=results[4]
PROCESS_SLEEPING=results[6]
PROCESS_THREADS=results[8]
} else if ($0 ~ /^Load Avg:/) {
LOAD_AVG_5=results[3]
LOAD_AVG_10=results[4]
LOAD_AVG_15=results[5]
} else if ($0 ~ /^CPU usage:/) {
CPU_USER=results[3]
CPU_SYS=results[5]
CPU_IDLE=results[7]
} else if ($0 ~ /^SharedLibs:/) {
SHARED_LIBS_RESIDENT=results[2]
SHARED_LIBS_DATA=results[4]
SHARED_LIBS_LINKEDIT=results[6]
} else if ($0 ~ /^MemRegions:/) {
MEM_REGIONS_TOTAL=results[2]
MEM_REGIONS_RESIDENT=results[4]
MEM_REGIONS_PRIVATE=results[6]
MEM_REGIONS_SHARED=results[8]
} else if ($0 ~ /^PhysMem:/) {
PHYSMEM_WIRED=results[2]
PHYSMEM_ACTIVE=results[4]
PHYSMEM_INACTIVE=results[6]
PHYSMEM_USED=results[8]
PHYSMEM_FREE=results[10]
} else if ($0 ~ /^VM:/) {
VM_SIZE=results[2]
VM_FRAMEWORK_SIZE=results[4]
VM_PAGE_IN=results[7]
VM_PAGE_OUT=results[9]
} else if ($0 ~ /^Networks:/) {
NETWORK_OUT=results[5]
NETWORK_IN=results[3]
} else if ($0 ~ /^Disks:/) {
DISK_READ=results[2]
DISK_WRITE=results[4]
} else if ($0 ~ /^$/) {
exit 0;
}
}
}

function ShowCPUInfo() {
print "===[ CPU ]==="
print "User  : "CPU_USER
print "System: "CPU_SYS
print "Idle  : "CPU_IDLE
}

function ShowProcessInfo() {
print "===[ Process ]==="
print "Total   : "PROCESS_TOTAL
print "Running : "PROCESS_RUNNING
print "Sleeping: "PROCESS_SLEEPING
print "Threads : "PROCESS_THREADS
}

function ShowPhysMemInfo() {
print "===[ Phys Mem ]==="
print "Wired   : "PHYSMEM_WIRED
print "Active  : "PHYSMEM_ACTIVE
print "INACTIVE: "PHYSMEM_INACTIVE
print "USED    : "PHYSMEM_USED
print "FREE    : "PHYSMEM_FREE
}

function ShowVMemInfo() {
print "===[ Virtual Mem ]==="
print "Total    : "VM_SIZE
print "Framework: "VM_FRAMEWORK_SIZE
print "Page In  : "VM_PAGE_IN
print "Page Out : "VM_PAGE_OUT
}

function ShowNetworkInfo() {
print "===[ Network ]==="
print "In : "NETWORK_IN
print "Out: "NETWORK_OUT
}

Post Footer automatically generated by wp-posturl plugin for wordpress.

Tags: , , , ,

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2010-2012 Jelly's Blog All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.0.2, from BuyNowShop.com.

Jelly's Blocnzz&51la for wordpress,cnzz for wordpress,51la for wordpress