Simple Bash script for reading size of Volume groupe.
Hey guys,
What is a simple bash script to read the size of a particular volume group and if that volumegroupe is at 50G big to send an email to user@mail.adress.com. I guess something like... if storeage-device > 50G full; then >> send email to user@mail.adress.com fi I know that that is totally wrong in terms of how its written. but Something like that? My scripting skills suck :( Thank! |
Start with df and awk or maybe cut
For a great resource on bash http://www.tldp.org/guides.html and look for the Advanced Bash Scripting Guide. Then post back here when you've something you've tried and ask for help with it. |
Quote:
on CLI if i do a #df /dev/mapper/volgoruptest it gives me the size of that voulme group and that is part of what i am looking for but how do i implement that on to a script? that says if this volumegroup is at 50G big than send an email to the mail server.. |
Quote:
|
Quote:
|
Quote:
|
Quote:
disk=$(df / | grep / | awk '{ print $5}' | sed 's/%//g') size=50 if [ "$disk" -gt "$size" ] ; then mail -s 'Disk Space Alert' user@mail.adress fi |
Quote:
See, wasn't so hard to go and copy some other script. Oh, and by the way, your script is wrong, and not what you asked for. |
Quote:
You've gotta do what you gotta do. The main point to it was so i can get a preview of how it would look. I think thats been accomplished here. I just tried it on my test machine after tweaking it and it works great. |
Quote:
|
The reason for asking is that the script you posted works on relative values (in your case % used) rather than the absolute value (50G) that you initially asked for.
|
google is a wonderful thing isnt it. But for your satisfaction here is the full script.
#!/bin/bash File=$(df /somefile | grep / | awk '{ print $5}' | sed 's/%//g') percentage=90 if [ "$File" -gt "$percentage" ] ; then mail -s 'Disk Space Alert' user@mail.adress << EOF free space is critically low. Used: $File% EOF fi originally wanted to get the size of a VG but this will get the job done as well. |
Hi Waris,
Great work! If you're satisfied with the script that it solves your problem, please consider marking the thread as solved to help future searches see a solved issue they could possibly benefit from. Perhaps also edit your last post to put [code][/code] tags around the code to separate it clearly and maintain any formatting. |
Usually percentages are better anyway. Fairly similar to what I'd do except I'd have passed the volume and percentage as variables and fully pathed the commands to make it a bit more robust when used in cron
Congratulations on getting there though. |
Quote:
Thanks, i just needed something imediate for now. But that is a good idea, i will disect this code on my own time to make it more robust like you said set variables and see if i can make it simpler. thank you for your input. |
All times are GMT -5. The time now is 11:53 PM. |