Solved

script to check server load

Posted on 2011-09-17
2
449 Views
Last Modified: 2013-12-16
hello there,
I would like to know how can I create a little tool that can check server load every minute and if the server loads is more than 10
then I would like to rename a dir.. how can I do that on centos v5.6?
0
Comment
Question by:XK8ER
2 Comments
 
LVL 77

Expert Comment

by:arnold
ID: 36554789
you can use cron to run script to check topm -n 1, uptime, and then use the information to do what is the effect of renaming a directory?
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 36554792
Hi,

I assume that you're talking about the 1-minute average load as displayed by "uptime"?

If so, you could run this script in background which would check every minute and  sleep inbetween:


#!/bin/sh
while :
  do
   if [[ $(uptime | awk '{print int($10)}') -gt 10 ]]; then
    echo Load greater 10, renaming ...
    echo mv olddir newdir
    exit
   fi
   sleep 60
  done

Please note that the script exits once a load of 10 has been reached,
to avoid running the now useless mv command over and over.

Note further that I put echo in fron of the mv statement, to allow testing.
Remove it when you're satified with the outcome.

Run this script like this:

nohup /path/to/script >/path/to/log 2>&1 &

An alternative could be running a modified version (without "while" and "sleep") of the script every minute via cron.
Should you like this idea we must take care, however, to avoid useless executions!

wmp
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

803 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