Solved

script to check server load

Posted on 2011-09-17
2
443 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 76

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now