LinuxQuestions.org
Review your favorite Linux distribution.
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 01-25-2018, 01:44 PM   #1
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Rep: Reputation: Disabled
Checking free space


Is it possible to run a small script to check for the free space on a drive an then send an email with the information?

Any help is highly appreciated!
 
Old 01-25-2018, 01:49 PM   #2
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,286

Rep: Reputation: 218Reputation: 218Reputation: 218
df checks; mail sends:

Code:
df | mail -s"free space on your drives" banana@fruit.com
 
1 members found this post helpful.
Old 01-25-2018, 01:50 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 21,959

Rep: Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827
Quote:
Originally Posted by trickydba View Post
Is it possible to run a small script to check for the free space on a drive an then send an email with the information?
Yes, very possible. Just write the script and you can put it in CRON to run periodically. Since you've been using Linux for a while now, I'm sure you probably know you can easily write/schedule a script or program to do pretty much whatever you'd like.

Or are you asking someone to write the script for you?
 
Old 01-25-2018, 02:02 PM   #4
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
RandomTroll gave me a starter. Looks like it would do what I need. I'll be running the command from within Oracle EDQ as an External Task. I can schedule it in EDQ cause I don't think I have permission to create CRONs. I never created one anyways but I suspect it's easy 8.)
 
Old 01-25-2018, 02:04 PM   #5
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@ RandomTroll..... works great, but let's say I want it to send me an email when it's at a certain percentage full?
 
Old 01-25-2018, 02:18 PM   #6
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I looked up how to create a CRON job. Looks easy, I might try to do it within Linux only.
 
Old 01-25-2018, 03:29 PM   #7
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I actually got this resolved but I want to insert the code the right way. I've done it before but I forgot. Can someone tell me how to insert code the correct way?
 
Old 01-25-2018, 04:10 PM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,144

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by RandomTroll View Post
df checks; mail sends:

Code:
df | mail -s"free space on your drives" banana@fruit.com
well I'll be a monkey's uncle, that even worked for gmail.com
 
Old 01-26-2018, 10:40 AM   #9
giis
Member
 
Registered: Nov 2013
Location: Third Rock from Moon
Distribution: RPM/DEB based and LFS
Posts: 73

Rep: Reputation: Disabled
Quote:
Originally Posted by trickydba View Post
I actually got this resolved but I want to insert the code the right way. I've done it before but I forgot. Can someone tell me how to insert code the correct way?
Can you post your script? It will help others to understand the issue. You have problem with crontab entries?
 
1 members found this post helpful.
Old 01-26-2018, 11:11 AM   #10
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,093

Rep: Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142
what do you want to insert exactly and where to?
 
1 members found this post helpful.
Old 01-29-2018, 08:01 AM   #11
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@giis....I would post my code but I forgot how to create that box to put the code into. Concerning CRON jobs I haven't tried yet to determine whether or not I have the permissions to create CRON jobs.
 
Old 01-29-2018, 08:06 AM   #12
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,093

Rep: Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142Reputation: 4142
[code]here comes your code[/code]
every user can configure cron entries for her/himself.
 
1 members found this post helpful.
Old 01-29-2018, 08:12 AM   #13
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 21,959

Rep: Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827Reputation: 5827
Quote:
Originally Posted by trickydba View Post
@giis....I would post my code but I forgot how to create that box to put the code into. Concerning CRON jobs I haven't tried yet to determine whether or not I have the permissions to create CRON jobs.
Sorry, but again (as pointed out earlier, which you ignored), you've been a Linux user and have been registered here for some time. Hovering over the buttons on the top of the posting window will pop up a tool-tip, telling you which one is for CODE tags, which YOU HAVE USED BEFORE, SEVERAL TIMES:
https://www.linuxquestions.org/quest...ux-4175608319/
https://www.linuxquestions.org/quest...er-4175608264/

So far, you've not posted anything that you've written/done/tried, and you have asked about CRON in the past as well, and said that you CANNOT USE IT. So writing a script and using CODE tags are all things you've done in the past. Why is this task different/harder for you?
https://www.linuxquestions.org/quest...er-4175608264/
https://www.linuxquestions.org/quest...hs-4175597217/
 
1 members found this post helpful.
Old 01-31-2018, 10:15 AM   #14
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@TBOne.... Not ignoring you. I was so used to using the Quick Reply which is why I didn't see it. Thank you for your help and patience!

This is my code that resolved my issue
Code:
#!/bin/bash

#admin email account
ADMIN="youremail"

# set usage alert threshold
THRESHOLD=65

#hostname
HOSTNAME=$hostname

#mail client
MAIL=/bin/mail

# store all disk info here
EMAIL=""

for line in $(df -hP | egrep '^/dev/' | awk '{ print $6 "_:_" $5 }')
do

        part=$(echo "$line" | awk -F"_:_" '{ print $1 }')
        part_usage=$(echo "$line" | awk -F"_:_" '{ print $2 }' | cut -d'%' -f1 )

        if [ $part_usage -ge $THRESHOLD -a -z "$EMAIL" ];
        then
                EMAIL="$(date): Running out of diskspace on $HOSTNAME\n"
                EMAIL="$EMAIL\n$part ($part_usage%) >= (Threshold = $THRESHOLD%)"

        elif [ $part_usage -ge $THRESHOLD ];
        then
                EMAIL="$EMAIL\n$part ($part_usage%) >= (Threshold = $THRESHOLD%)"
        fi
done

if [ -n "$EMAIL" ];
then
        echo -e "$EMAIL" | $MAIL -s "Alert: Partition(s) almost out of diskspace on $HOSTNAME" "$ADMIN"
fi
 
Old 01-31-2018, 10:17 AM   #15
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I was under the impression that you needed elevated access to create a CRON job, I was wrong. Thank you everyone for your outstanding and speedy help!
 
  


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
Help removing free space to create Raw free space nightmare55 Linux - Newbie 11 10-01-2009 03:07 AM
Checking for free space of unmounted partitions (cli) easuter Linux - Software 2 08-10-2007 01:17 AM
Not enough free space on hard drive with 50g of free space??? auoq SUSE / openSUSE 5 10-13-2004 08:21 PM
Formating free space: WinXP pro and RH9 dualboot with free space on 3rd drive Vermicious Linux - General 2 03-22-2004 05:10 AM
Checking free disk space hackersapien Linux - Newbie 2 08-05-2003 01:38 AM

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

All times are GMT -5. The time now is 04:38 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration