• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

While load average > 2...

Hello,

How can I have this loop in shell:

while this minute load average is bigger than 2.0, execute the code within the loop.

Thanks.
0
everactive
Asked:
everactive
  • 2
3 Solutions
 
TintinCommented:
Here you go
while [ -n "$(awk '$1 > 2 {print $1}' /proc/loadavg)" ]
do
   ..
done

Open in new window

0
 
ozoCommented:
#!/bin/bash
while uptime | awk '{exit ($(NF-2)<2.0)}' ; do
 code
done
0
 
vikas_madhusudanaCommented:

var =`uptime | cut -d "," -f 3 | cut -d " " -f 5`
while [ $var -gt 2 ]
do

var =`uptime | cut -d "," -f 3 | cut -d " " -f 5`
done

0
 
TintinCommented:
vikas, please note there are a number of problems with your suggestion


1.  Invalid syntax due to spaces before the =

2.  The cut doesn't extract the 1 min average

3.  Even if the cut was correct, the while loop would still run if the average was between 2.01 and 2.99, which it shouldn't
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now