I need help writing script to monitor the hard disk space
-Hello,
I was wondering if some one here kind a enough to help me whip up this Linux script to monitor the local hard disk space for shortage. I would like the script to text me on my pager if the disk space reached the threshold. Please help a newbie. Thank you in advance. xmdms |
Do you have any (pseudo) script lines you could show? That way it's easier to help and correct. If not then you could familiarise yourself with 'du' output and how to access a pager (e-mail) and then whip up some (pseudo) script lines?
|
Do you have any language preferences? ksh, bash, Perl etc?
|
I think there are already applications that can do this for you. So you may want to search around for them. However, if you really want to do it yourself, it is pretty straightforward:
I'm not going to write the script for you but I have some ideas where you can start. First, 'df' command will give you listing like this: Code:
Filesystem 1K-blocks Used Available Use% Mounted on To get it to 'monitor', set up a cron job to run the script however often you need to (every 5-15min would probably be fine, it's up to you). Good Luck! |
Quote:
I would prefer bash script. Would you guys have a sample script that I can examing and modify from there?? So far, this is what I have; #!/bin/bash RECIPENTS="your_name@dot.com" df -h I need serious help. Thanks, |
crc123's description is good. You just need to start putting it together, using these:
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ http://www.adminschoice.com/docs/cro...Crontab%20file Have a crack at it and come back if you get stuck. Note that only you can decide which SMS/Pager system to use, and you have to get the relevant sw and read the docs. |
Quote:
df: to get disk usage info grep: to find lines that contain words/phrases you pass in awk or sed: to parse the lines to find specific info on them (percentage) mail: to mail to your phone/pager cron: to run automatically if you don't feel like reading through those pages, you use the 'man' command to read the manual pages of any of these programs. Use 'man man' if you don't know how to use man. lol |
Quote:
Here's what I have and it's working; RECIPENTS="xmdms@yahoo.com" typeset -i error="92" if [ -e \tmp\space.out ]; then rm \tmp\space.out fi for disk in `mount | egrep '^/dev' | egrep -iv 'cdrom|proc|sys|pts' |awk '{print $3}'` do typeset -i diskUsage=`df -h $disk|cut -c40-42|grep -i [^a-z]` if [ "$diskUsage" -ge "$error" ]; then echo "Disk usage $disk exceeded the threshold of $diskUsage%" >> \tmp\space.txt fi done if [ -e \tmp\space.out ]; then message=`cat \tmp\space.out` fi if [ ${#message} -gt 0 ]; then cat \tmp\space.out | mail -s "Disk Usage Report for: $HOSTNAME" $RECIPENTS fi I do get the e-mail stating the threshold been exceeded. However, I get one single text line displayed for multiple devices in question. So, how do I add a tab or break line in my email? Example below: Currently: Disk usage /u01 exceeded the threshold of 96% Disk usage /u02 exceeded the threshold of 92% I would like to be: Disk usage /u01 exceeded the threshold of 96% Disk usage /u02 exceeded the threshold of 92% Thanks much!!! |
I'd use the -s switch to check the file size: http://www.tldp.org/LDP/abs/html/fto.html
The newline thing is odd. A similar check on my box locally works ok. Maybe its a yahoo thing? |
Quote:
Also, great job reading and LEARNING :). |
Quote:
Many thanks!! |
Okay, let's make this more interesting or I might say more technical challenge....Well, maybe to me (-:
Ok, after I have the script all worked out. Now, I would like to run this script from one (1) main server to monitor my three (3) other Linux servers. How or where would I go about remote monitoring between Linux servers?? Again, thanks for all your help and wisdom. Jorge |
Use 'ssh' to run the commands on remote computers. However, to get it to work in scripts, you will have to set it up to do secure passwordless logins. Google 'ssh without password'.
|
Quote:
~Many thanks!! |
Quote:
1) ssh-keygen -t dsa (or rsa) 2) press enter until prompt comes again. 3) two files will be in $HOME/.ssh directory. id_rsa id_rsa.pub 4) now simply copy the content of this file, to the $HOME/.ssh/authorized_keys file of the other server. |
All times are GMT -5. The time now is 09:53 PM. |