Должно работать на любом терминале поддерживающем VT Escape
последовательности, проверено в Linux, True64 , HP-UX и Соларисе .
#!/bin/ksh
SLEEP=$1
FIELD=$2
[ -z "$1" ] && SLEEP=10
[ -z "$2" ] && FIELD=1
stty_save=`stty -g`
trap "stty $stty_save ; exit; " 2
stty sane
clear
lines=`tput lines`
lines=$((lines-5))
DATE=`date '+%H:%M:%S'`
echo "\t\t`tput rev``hostname` TOP $lines PROCESESS at $DATE every $SLEEP seconds`tput sgr0`"
tput bold
case `uname` in
Linux) PS_COMMAND="ps -e -o pcpu= -o cputime= -o user= -o uid= -o pid= -o pmem= -o rssize= -o comm="
HEADER_COMMAND="ps f -p $$ -o pcpu,cputime,user,uid,pid,pmem,rssize,command"
;;
HP-UX) UNIX95=1
export UNIX95
PS_COMMAND="ps -e -o pcpu= -o time= -o user= -o uid= -o pid= -o vsz= -o sz= -o comm="
HEADER_COMMAND="ps -p $$ -o pcpu,time,user,uid,pid,vsz,sz,comm"
;;
SunOS) HEADER_COMMAND="ps -f -p $$ -o pcpu,time,user,uid,pid,pmem,rss,comm"
PS_COMMAND="ps -e -o pcpu= -o time= -o user= -o uid= -o pid= -o pmem= -o rss= -o comm="
;;
*) PS_COMMAND="ps -ef -o pcpu=,cputime=,user=,uid=,pid=,pmem=,rssize=,comm="
HEADER_COMMAND="ps -f -p $$ -o pcpu,cputime,user,uid,pid,pmem,rssize,command"
;;
esac
$HEADER_COMMAND | head -1
tput sgr0
while [ true ] ; do
tput cup 2 0
tput ed
$PS_COMMAND | sort -r -n -k"$FIELD" | head -$lines
sleep $SLEEP
done
|