Skip to content

Instantly share code, notes, and snippets.

@soohyunc
Created June 10, 2013 08:42
Show Gist options
  • Save soohyunc/5747313 to your computer and use it in GitHub Desktop.
Save soohyunc/5747313 to your computer and use it in GitHub Desktop.
System Stats
#!/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