Solved

script to check server load

Posted on 2011-09-17
2
452 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
[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 Comments
 
LVL 78

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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.

749 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