LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-24-2017, 10:45 AM   #1
Waris
Member
 
Registered: May 2017
Distribution: Centos 6,7 and Windows
Posts: 40

Rep: Reputation: Disabled
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!
 
Old 10-24-2017, 11:05 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,185

Rep: Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377
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.

Last edited by TenTenths; 10-24-2017 at 11:06 AM.
 
Old 10-24-2017, 11:14 AM   #3
Waris
Member
 
Registered: May 2017
Distribution: Centos 6,7 and Windows
Posts: 40

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
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.

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..
 
Old 10-24-2017, 11:21 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,185

Rep: Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377
Quote:
Originally Posted by Waris View Post
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..
Use awk or cut to get the used size and then compare that to the value for 50G (53687091200) and then use sendmail to send a mail.
 
Old 10-24-2017, 11:28 AM   #5
Waris
Member
 
Registered: May 2017
Distribution: Centos 6,7 and Windows
Posts: 40

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
Use awk or cut to get the used size and then compare that to the value for 50G (53687091200) and then use sendmail to send a mail.
I have a bit of a hard time writing that into script. Could you please write it for me?
 
Old 10-24-2017, 11:33 AM   #6
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,185

Rep: Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377
Quote:
Originally Posted by Waris View Post
I have a bit of a hard time writing that into script. Could you please write it for me?
Sure, $60/hour
 
Old 10-24-2017, 11:50 AM   #7
Waris
Member
 
Registered: May 2017
Distribution: Centos 6,7 and Windows
Posts: 40

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
Sure, $60/hour
haha good one dude. But ive been able to come up with something.


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
 
Old 10-24-2017, 11:55 AM   #8
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,185

Rep: Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377
Quote:
Originally Posted by Waris View Post
Quote:
Originally Posted by TenTenths View Post
Sure, $60/hour
haha good one dude. But ive been able to come up with something.
Just quoting you what I'm normally paid to do linux admin stuff :P

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.
 
Old 10-24-2017, 12:05 PM   #9
Waris
Member
 
Registered: May 2017
Distribution: Centos 6,7 and Windows
Posts: 40

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by TenTenths View Post
Just quoting you what I'm normally paid to do linux admin stuff :P

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.

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.
 
Old 10-24-2017, 12:10 PM   #10
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,185

Rep: Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377
Quote:
Originally Posted by Waris View Post
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.
So what did you tweak to get it to work properly?
 
Old 10-24-2017, 12:14 PM   #11
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,185

Rep: Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377
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.
 
Old 10-24-2017, 12:20 PM   #12
Waris
Member
 
Registered: May 2017
Distribution: Centos 6,7 and Windows
Posts: 40

Original Poster
Rep: Reputation: Disabled
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.

Last edited by Waris; 10-24-2017 at 01:41 PM.
 
Old 10-24-2017, 12:26 PM   #13
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,320
Blog Entries: 13

Rep: Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372Reputation: 4372
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.
 
Old 10-24-2017, 12:26 PM   #14
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,185

Rep: Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377
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.
 
Old 10-24-2017, 01:45 PM   #15
Waris
Member
 
Registered: May 2017
Distribution: Centos 6,7 and Windows
Posts: 40

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
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.

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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash Script - Reading User Input while Processing output from Command within Bash cleeky Linux - General 5 05-27-2014 02:57 PM
How to get some bash scripts into a simple bash script with some echo and if statement. y0_gesh Programming 3 03-01-2012 09:46 AM
comment sauvegarder un groupe de volume coolloo_djack Linux - Hardware 3 02-10-2010 06:49 AM
reading file, bash script marri Programming 3 11-15-2004 09:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration