Tiny Core Linux
Tiny Core Base => TCB Q&A Forum => Topic started by: wolf_core on August 26, 2012, 02:15:23 PM
-
Hi, i have a script that use the code below to show cpu usage in a web page, the code is write for arch linux, how can i modify the code to extract the CPU data usage in Tiny Core?
$CPUUSE="ps aux|awk 'NR > 0 { s +=$3 }; END {print \"cpu %\",s}' | awk '{ print $3 }'";
Thanks in advance Luca
-
You might want to look into procps or GNU ps, as busybox ps does not provide cpu output.
-
Maybe grab it from top?
-
good surgestion curaga
$top -n 1 | grep CPU: | grep -v grep | awk ' { print $1, $8, $9 } '
wondering how you tend to use the VAR maybe you can save a step by using cmd substitute (`) instead of quoting (") depending on what you do afterwards with the VAR
-
Hi ananix
I think will work:
$CPUUSE=echo `top -n 1 | grep CPU: | grep -v grep | awk ' { print $1, $8, $9 } '`
Or you might have to move the first ` in front of echo
-
Hi Rich i meant if he just needs a VAR with the result he could use
VAR=`top -n 1 | grep CPU: | grep -v grep | awk ' { print $1, $8, $9 } '`
Another consideration, one should also use head and tail instead when knowing line number to avoid miss graps of CPU:
-
Thanks everybody, i have try with all the solutions shows upside, but no data is shown in the web page. The best data output is xx.x% obtained with the code below but i think that the script use a data xx.x without % sign.
Now I have asked to the script the author how the $CPUUSE should be valorized to show data in the web page.
$CPUUSE=`top -n 1 | grep CPU: | grep -v grep | awk ' { print $2 } '`
Thanks Luca
-
Agreed, preferable if busybox's top can be used rather than procps or GNU ps.
-
The percent sign is easy to remove, use sed for example:
echo '30%' | sed 's@%@@g'
-
Thanks curaga I will try
$CPUUSE="(float)`top -n 1 | grep CPU: | grep -v grep | awk ' { print $2 } ' | sed 's@%@@g'`" ;
the script author say that $CPUUSE, should output a float number without any % sign.
Thanks Luca