?
Solved

While load average > 2...

Posted on 2010-01-11
4
Medium Priority
?
270 Views
Last Modified: 2013-12-26
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
Comment
Question by:everactive
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 1600 total points
ID: 26281664
Here you go
while [ -n "$(awk '$1 > 2 {print $1}' /proc/loadavg)" ]
do
   ..
done

Open in new window

0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 300 total points
ID: 26281682
#!/bin/bash
while uptime | awk '{exit ($(NF-2)<2.0)}' ; do
 code
done
0
 
LVL 7

Assisted Solution

by:vikas_madhusudana
vikas_madhusudana earned 100 total points
ID: 26281727

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
 
LVL 48

Expert Comment

by:Tintin
ID: 26288633
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Utilizing an array to gracefully append to a list of EmailAddresses
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question