corz.org uses cookies to remember that you've seen this notice explaining that corz.org uses cookies, okay!
corz.org text viewer..
[currently viewing: / public/ linux/ usr/ local/ bin/ sys.sh - raw]
calc_uptime() {
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="[01;32m uptime:[00m [01;33m$gw$wa$wdelim$gd$da$ddelim$gh$ha$hdelim$gm$ma$mdelim$sec second$sa[00m"
}
if [ "$1" = '' ]; then
clear
echo
echo " [01;33mview which system /proc information?[00m[01;35m"
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 "[00m"
echo " [01;32mnote:[00m [01;36myou can add these on the command line, eg.. [00m[01;35m sys u[00m"
echo " [01;36m which would display your uptime directly on your screen[00m"
echo " [01;30m"
read procwhat
if [ "$procwhat" = '' ]; then echo "[01;31m nothing selected![00m"; echo; exit; fi
if [ "$procwhat" = 'ks' ]; then out=f; fi
if [ "$out" != 'f' ]; then
echo
echo " [01;33moutput to file? (f), or screen? (just hit enter) [00m"
echo
echo " [01;32mnote:[00m [01;36myou can add this on the command-line, too, eg.. [00m [01;35msys u f[00m"
echo " [01;36m otherwise sys defaults to screen output[00m"
echo " [01;30m"
read out
echo "[00m"
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 "[01;32m"; df -h; echo "[00m"; 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 "[01;33mmodule size used by..[00m" ;;
'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 "[01;31munknown option![00m"; echo; exit
esac
if [ "$2" = 'f' ] || [ "$out" = 'f' ]; then
echo "${output}" > ~/sys.out
echo "[01;33moutput has been saved to[00m [01;35m~/sys.out[00m"
else
echo
echo "[01;33m${output}[00m"
echo
fi
exit 0