Ну вот , ЭТО моргает гораздо меньше :)
#!/bin/ksh
SLEEP=$1
FIELD=$2
[ -z "$1" ] && SLEEP=5
[ -z "$2" ] && FIELD=1
stty_save=`stty -g`
trap "stty $stty_save ; controlC ; exit; " EXIT
trap "eval `resize`;lines=`tput lines`; cols=`tput cols`;" WINCH
stty sane
clear
lines=`tput lines`
lines=$((lines-5))
date=`date '+%H:%M:%S'`
DATE=$date
REVERSE=`tput rev`
HOSTNAME=`hostname`
RESET=`tput sgr0`
UPTIME=`uptime | awk -F"," '{print $4 $5 $6 }' | awk -F":" '{print $2}'`
RHEAD="echo \t\t$REVERSE $HOSTNAME TOP $lines PROCESESS at $DATE every $SLEEP sec $UPTIME $RESET"
#echo $RHEAD
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 command="
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=,command="
HEADER_COMMAND="ps -f -p $$ -o pcpu,cputime,user,uid,pid,pmem,rssize,command"
;;
esac
tput cup 1 0
$HEADER_COMMAND | head -1
tput sgr0
collect () {
if [ -x /home/tomko/bin/date.tom -a `uname` != Linux ];then
DATE_COMMAND="/home/tomko/bin/date.tom +%s"
else
DATE_COMMAND="date +%S"
fi
from=`$DATE_COMMAND`
rm -f /tmp/_col_.$$
$PS_COMMAND |cut -c -`tput cols` |sort -r -n -k"$FIELD" |head -$lines > /tmp/_col_.$$ &
UPTIME=`uptime | awk -F"," '{print $4 $5 $6 }' | awk -F":" '{print $2}' &`
wait
to=`$DATE_COMMAND`
}
controlC () {
rm -f /tmp/_col_.$$ 2>/dev/null
}
present () {
# cup positon cursor on x x
tput cup 0 0
# el clear to end of line
#tput el
DATE=`date '+%H:%M:%S'`
RHEAD="\t$REVERSE $HOSTNAME TOP $lines PROCESESS at $DATE every $SLEEP sec $UPTIME $RESET"
echo $RHEAD
tput cup 2 0
# ed clear to end of screen
tput ed
[ -f /tmp/_col_.$$ ] && {
cat /tmp/_col_.$$
rm -f /tmp/_col_.$$
}
}
OLDSLEEP=$SLEEP
while [ true ] ; do
collect
present
diff=$(($to-$from))
SLEEP=$(($SLEEP-$diff))
[ $SLEEP -lt 0 ] && SLEEP=0
sleep $SLEEP
SLEEP=$OLDSLEEP
done