On Monday 5 May 2008, 22:12, Alan McKinnon wrote:
> nazgul screenlets-0.0.2 # echo `uptime|grep days|sed 's/.*up
> \([0-9]*\) day.*/\1\/10+/'; cat /proc/cpuinfo|grep '^cpu MHz'|awk
> '{print $4"/30 +";}';free|grep '^Mem'|awk '{print $3"/1024/3+"}'; df
> -P -k -x nfs -x smbfs | grep -v '1024-blocks' | awk '{if ($1 ~
> "/dev/(scsi|sd)"){ s+= $2} s+= $2;} END {print s/1024/50"/15
> +70";}'`|bc|sed 's/\(.$\)/.\1cm/' 67.1cm
>
> Fascinating, most fascinating. I get 67.1cm! Longer than yours!
>
> Now, this command of your. Wazzitdo?
It builds a bc expression, which is then fed to bc and the result is
divided by 10 and has "cm" added to it.
uptime|grep days|sed 's/.*up \([0-9]*\) day.*/\1\/10+/'
This checks the uptime, and outputs "n/10+", where "n" is the uptime in
days. In my case, the expression is "2/10+".
cat /proc/cpuinfo|grep '^cpu MHz'|awk '{print $4"/30 +";}'
This outputs "n/30 +", where "n" is the CPU speed in mhz. In my case
(hyperthreding cpu) it outputs
3000.000/30 +
3000.000/30 +
free|grep '^Mem'|awk '{print $3"/1024/3+"}'
This outputs "n/1024/3+", where "n" is the "used memory" from free's
output. On my desktop, that is "1721716/1024/3+", but obvioulsy it
changes almost every time you run the command. Not sure why the used
memory is used instead of the total.
df -P -k -x nfs -x smbfs | grep -v '1024-blocks' | awk '{if ($1
~ "/dev/(scsi|sd)"){ s+= $2} s+= $2;} END {print s/1024/50"/15
+70";}'
This outputs "n/15 +70", where "n" is the sum of the 1024-blocks as per
df's output (excluding nfs and smbfs file systems), divided by 1024 and
further divided by 50. The block count of /dev/scsi* or /dev/sd* devices
is counted twice (not sure why though). On my system, the output
is "5313.33/15 +70".
So, the final expression fed to bc is
2/10+ 3000.000/30 + 3000.000/30 + 1721716/1024/3+ 5313.33/15 +70
bc does the math, and sed divides the result by 10 and adds "cm" to the
result. For me, that gives 118.4cm.
It would be interesting to know why Willie chose those values, those
scaling factors, and what's the purpose of the constants.
Nice script though! Thanks!
--
[email protected] mailing list