#!/bin/bash # # sys [v0.2] # # conveniently provides *nix system info from /proc # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # menu-driven or command-line read-out # usage: sys # # (c) 2005 (or @ corz.org ;o) # # ignore the internal structures, I'm just playing. # calc_uptime() { # show me a better way.. tdiff=${output} week=0;day=0;hour=0;min=0;sec=0 while [ ${tdiff} -ge 604800 ]; do week=$(( ${week} + 1 )); tdiff=$(( ${tdiff} - 604800)) done while [ ${tdiff} -ge 86400 ]; do day=$(( ${day} + 1 )); tdiff=$(( ${tdiff} - 86400)) done while [ ${tdiff} -ge 3600 ]; do hour=$(( ${hour} + 1 )); tdiff=$(( $tdiff - 3600 )) done while [ ${tdiff} -ge 60 ]; do min=$(( ${min} + 1 )); tdiff=$(( ${tdiff} - 60 )) done while [ ${tdiff} -ge 1 ]; do sec=$(( ${sec} + 1 )); tdiff=$(( ${tdiff} - 1 )) done if [ ${week} -ge 1 ]; then gw="${week} week"; wdelim=", "; if [ ${week} != 1 ]; then wa=s; fi fi if [ ${day} -ge 1 ]; then gd="${day} day"; ddelim=", "; if [ ${day} != 1 ]; then da=s; fi fi if [ ${hour} -ge 1 ]; then gh="${hour} hour"; hdelim=", "; if [ ${hour} != 1 ]; then ha=s; fi fi if [ ${min} -ge 1 ]; then gm="${min} min"; mdelim=", "; if [ ${min} != 1 ]; then ma=s; fi fi if [ ${sec} != 1 ];then sa=s; fi output=" uptime: $gw$wa$wdelim$gd$da$ddelim$gh$ha$hdelim$gm$ma$mdelim$sec second$sa" } if [ "$1" = '' ]; then clear echo echo " view which system /proc information?" echo echo " c - CPU info" echo " d - DMA's" echo " dv - devices" echo " f - filesystems (mounted + current implementations)" echo " i - i/o ports" echo " in - interrupts" echo " ks - exported kernel symbols (always to a file)" echo " l - load averages" echo " m - memory info" echo " mod - modules (like lsmod, but yellow)" echo " p - pci info" echo " s - stats" echo " u - uptime (human-readable)" echo " v - system version info" echo "" echo " note: you can add these on the command line, eg..  sys u" echo "  which would display your uptime directly on your screen" echo " " read procwhat if [ "$procwhat" = '' ]; then echo " nothing selected!"; echo; exit; fi if [ "$procwhat" = 'ks' ]; then out=f; fi if [ "$out" != 'f' ]; then echo echo " output to file? (f), or screen? (just hit enter) " echo echo " note: you can add this on the command-line, too, eg..  sys u f" echo "  otherwise sys defaults to screen output" echo " " read out echo "" fi else procwhat=$1 fi case $procwhat in 'c') output=`cat /proc/cpuinfo` ;; 'd') output=`cat /proc/dma` ;; 'dv') output=`cat /proc/devices` ;; 'f') output=`cat /proc/filesystems`; echo ""; df -h; echo ""; echo ;; 'i') output=`cat /proc/ioports` ;; 'in') output=`cat /proc/interrupts` ;; 'ks') output=`cat /proc/ksyms`; out=f ;; 'l') output=`cat /proc/loadavg` ;; 'lk') output=`cat /proc/locks`; ;; 'm') output=`cat /proc/meminfo`; ;; 'mod') output=`cat /proc/modules`; echo; echo "module size used by.." ;; 'p') output=`cat /proc/pci` ;; 's') output=`cat /proc/stat`;; 'u') output=`cat /proc/uptime | awk 'BEGIN { FS = "." } { print $(NF-2) }'`; calc_uptime ;; 'v') output=`cat /proc/version`;; 'misc') output=`cat /proc/misc` ;; *) echo "unknown option!"; echo; exit esac if [ "$2" = 'f' ] || [ "$out" = 'f' ]; then echo "${output}" > ~/sys.out echo "output has been saved to ~/sys.out" else echo echo "${output}" echo fi exit 0