Previouslistopts.tclNext
1 #!/bin/sh 2 # vim:set syntax=tcl:\ 3 # vim:set nowrap:\ 4 tclsh=`( for name in $(/bin/ls $(echo $PATH | sed 's/:/ /g') 2> /dev/null | egrep '^tclsh(step)?([0-9]+\.[0-9]+)([a-z][a-z])?$') ; do echo $name ; done ) | tail -1` ;\ 5 [ -z "$tclsh" ] && tclsh=tclsh ;\ 6 exec $tclsh "$0" ${1+"$@"}
   9 set options {}
Check for memory and cpu.

  15 if { [file readable /proc/meminfo] } {
  16    # Linux
  17    set fd [ open /proc/meminfo r ]
  18    while { ![eof $fd] } {
  19       gets $fd line
  20       if { [regexp {^Mem:} $line] } {
  21          lappend options "-mem"
  22       }
  23    }
  24    close $fd
  25 } else {
  26    # BSD
  27    if { [exec /usr/bin/vmstat] != "" } {
  28       lappend options "-mem"
  29       lappend options "-cpu"
  30    }
  31 }
Check for disks.

  37 if { [file readable /proc/stat] } {
  38    # Linux
  39    set fd [ open /proc/stat r ]
  40    while { ![eof $fd] } {
  41       gets $fd line
  42       if { [regexp {^disk_io: (.*)$} $line -> disks] } {
  43          foreach disk $disks {
  44             regexp {\(([0-9]+),([0-9]+)\).*} $disk -> maj min
  45             switch $maj {
  46                2       { set dev [ format "fd%d" $min ] }
  47                3       { set dev [ format "hd%c" [expr $min+97] ] }
  48                22      { set dev [ format "hd%c" [expr $min+99] ] }
  49                8       { set dev [ format "sd%c" [expr $min+97] ] }
  50                default { set dev [ format "\[%d,%d\]" $maj $min ] }
  51             }
  52             lappend options "-disk $dev"
  53          }
  54       } elseif { [regexp {^disk_rblk .*} $line] } {
  55          set pfd [ open "| grep { sd.} /proc/partitions" r ]
  56          set type h
  57          while { ![eof $pfd] } {
  58             gets $pfd line
  59             if { $line != "" } { set type s }
  60          }
  61          catch { close $pfd }
  62          for { set n 97 } { $n <= 100 } { incr n } {
  63             lappend options [ format "-disk %sd%c" $type $n ]
  64          }
  65       } elseif { [regexp {^cpu .*} $line] } {
  66          lappend options "-cpu"
  67       }
  68    }
  69    close $fd
  70 } else {
  71    # BSD
  72    set devs [ exec /usr/sbin/iostat -d | head -1 ]
  73    if { [regexp {^[a-z0-9 ]+$} $devs] } {
  74       foreach dev $devs {
  75          lappend options "-disk $dev"
  76       }
  77    }
  78 }
Check for network interfaces.

  84 if { [file readable /proc/net/dev] } {
  85    # Linux
  86    set fd [ open /proc/net/dev r ]
  87    while { ![eof $fd] } {
  88       gets $fd line
  89       if { [regexp {^ *(.*) *:} $line -> iface] } {
  90          lappend options "-if $iface"
  91       }
  92    }
  93    close $fd
  94 } else {
  95    # BSD
  96    set fd [ open "| /sbin/ifconfig -a" r ]
  97    while { ![eof $fd] } {
  98       gets $fd line
  99       if { [regexp {^([a-z0-9]+):} $line -> iface] } {
 100          lappend options "-if $iface"
 101       }
 102    }
 103    close $fd
 104 }
Output the findings.

 110 puts "\n$tcl_platform(os) $tcl_platform(osVersion)\n"
 111 foreach opt $options { puts $opt }
 112 puts ""