a bash script to check cpu usage?

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
divisionmd
Posts: 606
Joined: Sat 14 Jul 2007, 20:42

a bash script to check cpu usage?

#1 Post by divisionmd »

Hello,

Working on a few test programs here... html5 apps that are a bit buggy.. .anyone know how to:

Make a bash script to detect when cpu usage is 80% or more- then run a killall chrome command.?

thanks for help,
Johan

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#2 Post by Karl Godt »

while i_know_what_i_am_doing; do

Code: Select all

IDLE=`top -n1| grep -o -e '[0-9]*\% idle' |sed 's%[^[:digit:]]%%g'`
echo $IDLE
#45
sleep 1
done

User avatar
divisionmd
Posts: 606
Joined: Sat 14 Jul 2007, 20:42

#3 Post by divisionmd »

hello Karl Godt,

thanks for input - Got an error on char 19... but might be a typo doublechecking tomorrow first thing after coffeee...


best regards,
Johan

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#4 Post by Karl Godt »

code should work, but that above was on Racy-5.5,
which has Busybox-1.19.x or above
and my current 1.18.3 seems to need the -b option passed to top additionally
and does not show correct values: 95% of the time it is 100% idle or 0% though top without options in another console shows 80% idle.

check busybox version by issuing busybox in the console.

User avatar
divisionmd
Posts: 606
Joined: Sat 14 Jul 2007, 20:42

#5 Post by divisionmd »

Hello Karl,

- Worked perfectly - just made a typo...

Thanks for help,

Best regards,
Johan

Post Reply