Created
June 10, 2013 08:42
-
-
Save soohyunc/5747313 to your computer and use it in GitHub Desktop.
System Stats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/tclsh | |
# calculate system uptime | |
set host [lindex [split [exec hostname] "."] 0] | |
set ut [exec /usr/bin/uptime] | |
if {([lindex $ut 3] == "days,")||([lindex $ut 3] == "mins,")||([lindex $ut 3] == "hrs,")||([lindex $ut 3] == "day,")||([lindex $ut 3] == "min,")||([lindex $ut 3] == "hr,")} { | |
set up "[lindex $ut 2] [string trimright [lindex $ut 3] \",\"]" | |
} else { | |
set up [string trimright [lindex $ut 2] ","] | |
} | |
puts "up:\t$up" | |
# calculate system load | |
set load [string trimright [lindex $ut 9] ","] | |
if {$load == "averages:"} { | |
set load [string trimright [lindex $ut 10] ","] | |
} | |
if {$load == "average:"} { | |
set load [string trimright [lindex $ut 10] ","] | |
} | |
puts "load:\t$load" | |
# see users | |
set w [exec /usr/bin/w] | |
set lines [lrange [split $w "\n"] 2 end] | |
set users "" | |
foreach line $lines { | |
set user [lindex $line 0] | |
if {[string first $user $users]==-1} { | |
lappend users $user | |
} | |
} | |
puts "users:\t$users" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment