Jump to content


Photo

Linux HOWTO


  • Please log in to reply
1 reply to this topic

#1 Eraserheads

Eraserheads

    Immortal Member

  • Members
  • PipPipPipPipPip
  • 375 posts

Posted 05 August 2006 - 01:39 AM

How to find the biggest files on your hard-drive.


ls -l | sort +4n

Or, for those of you really scrunched for space this takes awhile but works great:


cd /
ls -lR | sort +4n

#2 Eraserheads

Eraserheads

    Immortal Member

  • Members
  • PipPipPipPipPip
  • 375 posts

Posted 28 September 2006 - 05:23 AM

Is there enough free space???

Here comes a short script which will check from time to time that there is enough free space available on anything which shows up in mount (disks, cdrom, floppy...)

If space runs out, a message is printed every X seconds to the screen and 1 mail message per filled device is fired up.

------------------------------------------------------------------------------------------------


#!/bin/sh

#
# $Id: check_hdspace,v 1.18 1996/12/11 22:33:29 root Exp root $
#

#
# Since I got mysterious error messages during compile when
# tmp files filled up my disks, I wrote this to get a warning
# before disks are full.
#
# If this stuff saved your servers from exploding,
# send praising email to zocki@goldfish.cube.net.
# If your site burns down because of this, sorry but I
# warned you: no comps.
# If you really know how to handle sed, please forgive me :o
#

#
# Shoot and forget: Put 'check_hdspace &' in rc.local.
# Checks for free space on devices every $SLEEPTIME sec.
# You even might check your floppies or tape drives. :o
# If free space is below $MINFREE (kb), it will echo a warning
# and send one mail for each triggering device to $MAIL_TO_ME.
# If there is more free space than trigger limit again,
# mail action is also armed again.
#

# TODO: Different $MINFREE for each device.
# Free /*tmp dirs securely from old junk stuff if no more free space.


DEVICES='/dev/sda2 /dev/sda8 /dev/sda9' # device; your put disks here
MINFREE=20480 # kb; below this do warning
SLEEPTIME=10 # sec; sleep between checks
MAIL_TO_ME='root@localhost' # fool; to whom mail warning


# ------- no changes needed below this line (hopefully) -------

MINMB=0
ISFREE=0
MAILED=""
let MINMB=$MINFREE/1024 # yep, we are strict

while [ 1 ]; do
DF="`/bin/df`"
for DEVICE in $DEVICES ; do
ISFREE=`echo $DF | sed s#.\*$DEVICE" "\*[0-9]\*""\*[0-9]\*" "\*## | sed s#" ".\*##`

if [ $ISFREE -le $MINFREE ] ; then
let ISMB=$ISFREE/1024
echo "WARNING: $DEVICE only $ISMB mb free." >&2
#echo "more stuff here" >&2
echo -e "\a\a\a\a"

if [ -z "`echo $MAILED | grep -w $DEVICE`" ] ; then
echo "WARNING: $DEVICE only $ISMB mb free. (Trigger is set to $MINMB mb)" \
| mail -s "WARNING: $DEVICE only $ISMB mb free!" $MAIL_TO_ME
MAILEDH="$MAILED $DEVICE"
MAILED=$MAILEDH
# put further action here like cleaning
# up */tmp dirs...
fi
elif [ -n "`echo $MAILED | grep -w $DEVICE`" ] ; then
# Remove mailed marker if enough disk space
# again. So we are ready for new mailing action.
MAILEDH="`echo $MAILED | sed s#$DEVICE##`"
MAILED=$MAILEDH
fi

done
sleep $SLEEPTIME

done

--------------------------------------------------------------------------------------------

Edited by Eraserheads, 28 September 2006 - 05:25 AM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users