Help with HD monitor script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with HD monitor script
# 1  
Old 04-09-2010
Help with HD monitor script

Hi,
I'm new to linux and I'm trying to compile a hard drive monitoring script. I've seen a few on the internet and I've attempted to stumble through but I'm stuck at my while/do scenario.
I assigned the variable NUM then took the percentage from my output and cut the % so it would be just a number. The partition line is from a sample script and I'm not sure if I even need that. I just want to get the script to work so then I can tweak it the way I want. I don't want anyone to write the script for me but a little help understanding where I'm going wrong would be great.

Code:
#!/bin/bash
ADMIN="email address"

ALERT=85

df -H | grep '^/dev/sda1'  | awk ' { print $5 " " $1 } ' | while read output;
do
  #echo $output
  NUM= $( echo $output | awk ' { print $1 } ' | cut -d '%' -f1 )
  partition= $(echo $output | awk ' { print $2 } ' )
  if [ $NUM -ge $ALERT ]; then
    echo "Running out of space \"$partition ($NUM%)\" on $(hostname) as on $(date)" |
    mail -s "Alert: Almost out of disk space $NUM"  $ADMIN
  fi
done


Last edited by Franklin52; 04-09-2010 at 12:44 PM.. Reason: Please use code tags!
# 2  
Old 04-09-2010
This is working for me. Include your admin mail id and mailx command and adjust the ALERT count

change this line also ^/dev/sda7

Code:
#!/bin/bash

ALERT=40

df -H | grep '^/dev/sda7'  | awk ' { print $5 " " $1 } ' | while read output;
do
  echo $output
  NUM=`echo $output | awk ' { print $1 } ' | cut -d '%' -f1 `
#echo $NUM
  partition=`echo $output | awk ' { print $2 } '`
  if [ $NUM -ge $ALERT ]; then
    echo "Running out of space \"$partition ($NUM%)\" on $(hostname) as on $(date)"
  fi
done


Last edited by itkamaraj; 04-09-2010 at 12:56 PM.. Reason: adding some more info
# 3  
Old 04-09-2010
Remove UUoC please Smilie
Code:
msg=$(df -H | awk 'int($5) > 84 && /\dev\/sda/{print $NF,$5,";"}')
if [ ! -z "$msg" ]; then
           echo $msg # Do something here.
fi

# 4  
Old 04-09-2010
You can read the variables like this:

Code:
#!/bin/bash
ADMIN="email address"

ALERT=85

df -H | awk '/^\/dev\/sda1/{print $1, int($5)}' | while read partition NUM
do
  if [ $NUM -ge $ALERT ]; then
    echo "Running out of space \"$partition ($NUM%)\" on $(hostname) as on $(date)" |
    mail -s "Alert: Almost out of disk space $NUM"  $ADMIN
  fi
done

# 5  
Old 04-09-2010
This one liner also do the samething

Code:
 disk_usage=`df -H | grep "/dev/sda7" |  awk '{print $5}' | cut -d"%" -f1` | if [ $disk_usage -ge 85 ]; then echo "disk usage is high";else echo "Disk usage is not high"; fi

# 6  
Old 04-09-2010
Quote:
Originally Posted by crocyson
Code:
NUM= $( echo $output | awk ' { print $1 } ' | cut -d '%' -f1 )
partition= $(echo $output | awk ' { print $2 } ' )

In your original script, the problem is the space after the "=".

Without that space, the shell parses that as a simple variable assignment (whose value is the result of the command substitution). With that space, the result of the command substitution is treated as a command to execute (with NUM/partition in its environment and set to a zero-length string).

Example:
Code:
$ greetings=$(echo hi)
$ echo $greetings
hi
$ greetings= $(echo hi)
-bash: hi: command not found

Hope that helps,
Alister

Last edited by alister; 04-09-2010 at 02:09 PM..
# 7  
Old 04-09-2010
Thanks for the tips guys. I'm omw to work now. Ill play with it in the morning and see if I run in to anymore trouble.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Script monitor website wth default tomcat script

Hi all, on our application server we have the following script that monitor the status of the website, my problem here is that i have edite the retries from 3 to 5, and the timewait to 120 second, so the script should check 5 times every 2 minutes, and if the fifth check fails it must restart... (0 Replies)
Discussion started by: charli1
0 Replies

2. Infrastructure Monitoring

Searching for Saas Monitor service which monitor my servers which are sitting in different providers

Sorry if this is the wrong forum Searching for Saas Monitor service which monitor my servers which are sitting in different providers . This monitor tool will take as less CPU as possible , and will send info about the server to main Dashboard. The info I need is CPU / RAM / my servers status (... (1 Reply)
Discussion started by: umen
1 Replies

3. Shell Programming and Scripting

Monitor the services by script

I developed for monitoring the network connections among the branch servers as I given below as script.But I don't know how to monitor the services through network script whether the services is running or not. eg : I want to check the postgres service for all the branch servers through network... (0 Replies)
Discussion started by: kannansoft1985
0 Replies

4. Shell Programming and Scripting

[Help] Script to monitor logs

Hello friends, as they are? First of all sorry for my poor English. I tell them what is my problem. I have the following script, which is basically what makes error search for a pattern within a folder containing logs. The script works fine, the problem is that whenever I find a pattern of new... (2 Replies)
Discussion started by: romanrsr
2 Replies

5. Shell Programming and Scripting

How to monitor a shell script called within a script?

HIi Guys... I am in a fix.... 1st the code : Script 123.sh looks like this : ./abc # a script which is getting called in this script while true do count=`ps -ef | grep abc | wc -l` if echo "abc is running sleep 10 fi done but the process is getting checked... (5 Replies)
Discussion started by: chatwithsaurav
5 Replies

6. UNIX for Dummies Questions & Answers

Monitor a script

Hi All, In a script I would like to check whether the current running command is completed in 1 hour or not. This i want to achieve inside the same script. I don't want to use separate script to monitor my current running script. eg. pseudocode; Command1 if command1>60 mins then... (7 Replies)
Discussion started by: Vicky5
7 Replies

7. Shell Programming and Scripting

Script to monitor Values

Hi All, I want a scrip to monitor values which is the out put of a certain command. Example is $ for (( c=1; c<15; c++ )); do cmu -O HTA -d HTTP-PROXY.tswebpxmp5.$c | grep -i active; done HTA_STATS_htaStatsDef.ifw_stats.streamStat.activeStreams : 2 ... (1 Reply)
Discussion started by: Siddheshk
1 Replies

8. Shell Programming and Scripting

Monitor script

Does anyone have a monitoring script in solaris that monitors the drives in an exclosure? The script should be in /bin/bash or /bin/sh thnks again This should be for solaris 10/11 looking for something that tells me a drive is down or offline.:confused: (0 Replies)
Discussion started by: walnutpony123
0 Replies

9. Shell Programming and Scripting

need help doing a script to monitor if files are go through

I am trying to do a shell script to check a folder and see if files are passing through. Now if a file did not pass through in the last 1 hour send an email. ftp----------> folder to monitor ----------->ftp Now the script that moves the file runs every sec in cron, so i do not know if i... (0 Replies)
Discussion started by: jonathan184
0 Replies
Login or Register to Ask a Question