Re: [SLUG] tload-workalike

From: Eben King (eben01@verizon.net)
Date: Tue Mar 24 2009 - 15:47:36 EST


On Tue, 24 Mar 2009, Eben King wrote:

> #! /bin/sh

Oops, forgot a few characters. Make that:

#! /bin/sh
sleeptime=5
ratio=20
ratio100=$((100/ratio))
ratioone=$((ratio-1))
while : ; do
   load100=`uptime | cut -f 4 -d :`
   load100=`echo ${load100%%,*} | tr -d .`
   xes=$(( ( 10#$load100 - ( 10#$load100 / 100 ) * 100 ) / ratio100 ))
   (
     for digit in `seq 1 ${load100%??}` ; do
       yes x | head -$ratioone ; echo '|'
     done
     yes x | head -$xes
   ) | tr -d '\n'; echo
   sleep $sleeptime
done

I have to put 10#$load100 because $load100 might start with a 0 and without
the 10# $(( )) tries to interpret it as octal and either gets the wrong
answer or blows up.

-- 
-eben   QebWenE01R@vTerYizUonI.nOetP   http://royalty.mine.nu:81

Hanlon's Razor: "Never attribute to malice that which can be adequately explained by stupidity." Derived from Robert Heinlein ----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:16:29 EDT