1: #!/usr/bin/tcl -n 2: 3: set inFile "status.xtml" 4: 5: proc singular {val {false "s"} {true ""}} { 6: if {$val==1} { return $true } else { return $false } 7: } 8: proc size {val {suffix "byte"}} { 9: set level 0 10: set prefixes [list "" kilo mega giga tera peta] 11: while {$val>1024} { 12: set val [expr $val/1024.0] 13: incr level 14: } 15: set val [expr int($val+0.5)] 16: return "$val [lindex $prefixes $level]$suffix[singular $val]" 17: } 18: 19: 20: set upId [open "/proc/uptime" r] 21: set info(uptime) [lindex [split [gets $upId] .] 0] 22: close $upId 23: foreach {var val} {mon 2592000 wks 604800 day 86400 hrs 3600 min 60 sec 1} { 24: set info(uptime.${var}) [expr $info(uptime)/${val}] 25: set info(uptime) [expr $info(uptime)-($info(uptime.${var})*${val})] 26: } 27: set ldId [open "/proc/loadavg" r] 28: set info(load) [gets $ldId] 29: close $ldId 30: set info(load.1) [lindex $info(load) 0] 31: set info(load.5) [lindex $info(load) 1] 32: set info(load.15) [lindex $info(load) 2] 33: set info(load.run) [lindex [split [lindex $info(load) 3] /] 0] 34: set info(load.sleep) [expr ([lindex [split [lindex $info(load) 3] /] 1])-$info(load.run)] 35: catch { 36: set info(users) [exec /usr/bin/users] 37: } 38: if {![info exists info(users)]} { set info(users) "" } 39: set info(users.count) [llength $info(users)] 40: set puser "" 41: set info(users.uniq) "" 42: foreach cuser [lsort $info(users)] { 43: if {$cuser!=$puser} { set puser $cuser; lappend info(users.uniq) $cuser } 44: } 45: set info(users.uniq.count) [llength $info(users.uniq)] 46: set info(host.fqdn) [info hostname] 47: set info(host.name) [lindex [split $info(host.fqdn) .] 0] 48: set info(host.domain) [string range $info(host.fqdn) [expr [string length $info(host.name)]+1] end] 49: set info(host.os) $tcl_platform(os) 50: set info(host.osver) $tcl_platform(osVersion) 51: set info(host.machine) $tcl_platform(machine) 52: set info(df) [lrange [split [exec /bin/df] \n] 1 end] 53: foreach item $info(df) { 54: set info(df.[lindex $item 0].name) [lindex $item 0] 55: set info(df.[lindex $item 0].size) [lindex $item 1] 56: set info(df.[lindex $item 0].used) [lindex $item 2] 57: set info(df.[lindex $item 0].free) [lindex $item 3] 58: set info(df.[lindex $item 0].mount) [lindex $item 5] 59: set info(df.[lindex $item 0].line) $item 60: } 61: if {$info(host.os)=="Linux"} { 62: if {[file exists /etc/slackware-version]} { set info(host.distribution) "Slackware" } 63: if {[file exists /etc/redhat-release]} { set info(host.distribution) "RedHat" } 64: if {[file exists /etc/mandrake-release]} { set info(host.distribution) "Mandrake" } 65: if {![info exists info(host.distribution)]} { set info(host.distribution) "Unknown" } 66: } 67: set cpuId [open "/proc/cpuinfo" r] 68: while {![eof $cpuId]} { 69: gets $cpuId ln 70: set ln [split $ln :] 71: set item [string trim [lindex $ln 0]] 72: set value [string trim [lindex $ln 1]] 73: set info(cpu.[lindex $item 0][lindex $item 1]) $value 74: } 75: close $cpuId 76: set memId [open "/proc/meminfo" r] 77: set info(mem.free) 0 78: while {![eof $memId]} { 79: gets $memId ln 80: set ln [split $ln :] 81: set item [string trim [lindex $ln 0]] 82: catch { set value [expr [string trim [lindex [lindex $ln 1] 0]]*1024] } 83: switch -- "$item" { 84: MemTotal { set info(mem.total) $value } 85: SwapTotal { set info(mem.swap.total) $value } 86: SwapFree { set info(mem.swap.free) $value } 87: MemFree { incr info(mem.free) $value } 88: Cached { incr info(mem.free) $value } 89: Buffers { incr info(mem.free) $value } 90: } 91: } 92: 93: if {[info exists env(HTTP_HOST)]} { 94: puts "Content-type: text/html\n" 95: } 96: set parseId [open $inFile r] 97: while 1 { 98: gets $parseId ln 99: if {[eof $parseId]} { break } 100: catch { puts [subst $ln] } err 101: # if {$err!=""} { puts stderr "error: $err" } 102: } 103: close $parseId 104: 105: 106: #puts "<PRE>[exec /bin/bash -c {ulimit -a}]</PRE>" |