View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 9 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Tue Apr 08, 2008 12:07 am 
Offline
Joined: Mon Mar 13, 2006 2:28 am
Posts: 143
Location: Brisbane, Australia
A script to send yourself an email if the remaining root disk space falls below your comfort level. Typically one would set this up as a cronjob. Uses sendEmail, which has been discussed here before.

Code:
#!/bin/bash

# Email me when root disk usage exceeds a specified percentage.

SENDER=mythtv@my.house
RECIPIENT=emailme@my.work
SMTP_SERVER=mail.my.isp
ALERT_PERCENTAGE=90        # 90% disk used, ~500mb remaining on stock install

HOSTNAME=`hostname`

REMAINING=`df / |awk '{print $5}' |tail -1 |sed s/%//`

if [ $ALERT_PERCENTAGE -lt $REMAINING ]; then
        df -h | sendEmail -f $SENDER -t $RECIPIENT -s $SMTP_SERVER -u "$HOSTNAME has ${REMAINING}% root disk space remaining."
fi

_________________
MBE/FE ~ R5F27 ~ Asus A8N-VM-CSM ~ AMD64 3500+ ~ 1GB RAM ~ 1.5TB Storage ~ Nova-T-500 ~ SH-S183A DVDRW ~ LC20M Case ~ iMON-Pad Remote
FE ~ Diskless ~ Asus M2NPV-VM ~ AMD X2 BE-2350 (45w) ~ 1GB RAM ~ TT Lanbox Lite ~ iMON-Pad Remote


Last edited by Kirk on Tue Apr 08, 2008 11:03 pm, edited 1 time in total.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 6:41 am 
Offline
Joined: Sun Jun 12, 2005 10:55 pm
Posts: 3161
Location: Warwick, RI
Hi,

Handy idea but to save postage, an osd alert works also. I have found any "anomaly" perceived or real is soon followed with a phone call from my wife :) I am sure an osd to the fact of something needs attention would invoke a similar phone call!

Mike


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 5:31 pm 
Offline
Joined: Mon Mar 13, 2006 2:28 am
Posts: 143
Location: Brisbane, Australia
Not a bad idea. I'll add that in shortly.

_________________
MBE/FE ~ R5F27 ~ Asus A8N-VM-CSM ~ AMD64 3500+ ~ 1GB RAM ~ 1.5TB Storage ~ Nova-T-500 ~ SH-S183A DVDRW ~ LC20M Case ~ iMON-Pad Remote
FE ~ Diskless ~ Asus M2NPV-VM ~ AMD X2 BE-2350 (45w) ~ 1GB RAM ~ TT Lanbox Lite ~ iMON-Pad Remote


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 9:37 pm 
Offline
Joined: Mon Jul 31, 2006 10:41 pm
Posts: 149
Thanks for the script.

Perhaps I'm misunderstanding, but by root usage, do you mean /.

If so then I'm getting an incorrect response from the from the df ... portion.

The tail command gives the last result only which in my case sda1 is for /myth/video.

I changed it a bit:

Code:
df /dev/[h,s]da1 | sed -n '/\/$/p' | awk '{print $5}' | sed s/%//


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 11:02 pm 
Offline
Joined: Mon Mar 13, 2006 2:28 am
Posts: 143
Location: Brisbane, Australia
Thanks mythedoff,

Yeah, I mean /

Looking back I don't know why I didn't just do 'df /' That should fix all cases.

Regards,
Kirk.

_________________
MBE/FE ~ R5F27 ~ Asus A8N-VM-CSM ~ AMD64 3500+ ~ 1GB RAM ~ 1.5TB Storage ~ Nova-T-500 ~ SH-S183A DVDRW ~ LC20M Case ~ iMON-Pad Remote
FE ~ Diskless ~ Asus M2NPV-VM ~ AMD X2 BE-2350 (45w) ~ 1GB RAM ~ TT Lanbox Lite ~ iMON-Pad Remote


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 09, 2008 9:56 am 
Offline
Joined: Sun Jun 12, 2005 10:55 pm
Posts: 3161
Location: Warwick, RI
Hi,

Taking the email sample, with a "couple of small changes", this works for an alert. Maybe have cron run it once an hour..
Code:
#!/bin/sh
# Drive space warning
#----------- adjust for monitor or tv--------------
lsmod |grep "ivtvfb "|cut -b1-6 >/tmp/tv
if [ "$(cat /tmp/tv)" = "ivtvfb" ]; then
fontsize="25"
fontcolor="lightyellow"
else
fontsize="34"
fontcolor="yellow"
fi
export DISPLAY=:0
export FONT="-adobe-helvetica-bold-*-*-*-$fontsize-*-*-*-*-*-*-*"
#-------------------------------------------------------------------------------
ALERT_PERCENTAGE=70        # 90% disk used, ~500mb remaining on stock install

HOSTNAME=`hostname`

REMAINING=`df / |awk '{print $5}' |tail -1 |sed s/%//`

if [ $ALERT_PERCENTAGE -lt $REMAINING ]; then
        date > /tmp/tts
        echo "$HOSTNAME has ${REMAINING}% root disk space remaining." >>/tmp/tts
        cat /tmp/tts | osd_cat --l=8 --delay=6 --font=$FONT --shadow=3  --color=$fontcolor  --pos=bottom$
fi


I just borrowed pieces from some of my other osd scripts.
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 09, 2008 2:50 pm 
Offline
Joined: Mon Mar 13, 2006 2:28 am
Posts: 143
Location: Brisbane, Australia
Ah, beat me to it.

Good one mjl :D

_________________
MBE/FE ~ R5F27 ~ Asus A8N-VM-CSM ~ AMD64 3500+ ~ 1GB RAM ~ 1.5TB Storage ~ Nova-T-500 ~ SH-S183A DVDRW ~ LC20M Case ~ iMON-Pad Remote
FE ~ Diskless ~ Asus M2NPV-VM ~ AMD X2 BE-2350 (45w) ~ 1GB RAM ~ TT Lanbox Lite ~ iMON-Pad Remote


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 09, 2008 3:11 pm 
Offline
Joined: Fri Oct 20, 2006 12:04 pm
Posts: 905
Location: LA, CA
Personally, I like the email... to each...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 09, 2008 4:47 pm 
Offline
Joined: Sun Jun 12, 2005 10:55 pm
Posts: 3161
Location: Warwick, RI
Hi,

We can make it optional :) I think this should work as I just borrowed some of Kirk's code and only re-arranged it a little.

Code:
#!/bin/sh
# Drive space warning script
#-------------------------------------------------------------
lsmod |grep "ivtvfb "|cut -b1-6 >/tmp/tv
if [ "$(cat /tmp/tv)" = "ivtvfb" ]; then
fontsize="25"
fontcolor="lightyellow"
else
fontsize="34"
fontcolor="yellow"
fi
export DISPLAY=:0
export FONT="-adobe-helvetica-bold-*-*-*-$fontsize-*-*-*-*-*-*-*"
#----------------------------------------------------------------
email=0                    # 1 or greater to enable email
show=1                     # 1 to show osd
date > /tmp/tts             # Nice to know when things happen
ALERT_PERCENTAGE=90        # 90% disk used, ~500mb remaining on stock install?
HOSTNAME=`hostname`
RREMAINING=`df / |awk '{print $5}' |tail -1 |sed s/%//`     # root status
MREMAINING=`df /myth |awk '{print $5}' |tail -1 |sed s/%//` # myth status

# root
if [ $ALERT_PERCENTAGE -lt $RREMAINING ]; then
        echo "WARNING, $HOSTNAME has ${RREMAINING}% root disk space remaining." >>/tmp/tts
        # bump flag
        email="$(($email + 1 ))"
        show="$(($show + 1 ))"
fi

ALERT_PERCENTAGE=85        # 85% myth partition used
REMAINING=`df /myth |awk '{print $5}' |tail -1 |sed s/%//`

# myth
if [ $ALERT_PERCENTAGE -lt $MREMAINING ]; then
        echo "$HOSTNAME has ${MREMAINING}%  disk space remaining for shows." >>/tmp/tts
        # bump flag
        #email="$(($email + 1 ))"
        #show="$(($show + 1 ))"
fi

# show it from here if flagged
if [ $show -gt "1" ]; then
        cat /tmp/tts | osd_cat --l=8 --delay=6 --font=$FONT --shadow=3  --color=$fontcolor  --pos=bottom --align=centre &
fi

# email it from here if flagged
if [ $email -gt "1" ]; then
#       Email me when root disk usage exceeds a specified percentage.
        SENDER=mythtv@my.house
        RECIPIENT=emailme@my.work
        SMTP_SERVER=mail.my.isp
        df -h | sendEmail -f $SENDER -t $RECIPIENT -s $SMTP_SERVER -u "$HOSTNAME has ${RREMAINING}% root disk space remaining."
        email=0
fi

#done

Just by setting switches you can have either, both or none.

Mike
Fixed a typo, actually a couple lines got truncated on me :( also watch for line wrapping if copy / paste


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: Google [Bot] and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu