Space problems are a common occurrence because applications are forever incresing in size. Often space problems can be caused by rouge processes or just careless users. Often the cause is obvious, but occasionally it can be a bit of a mystery.
After investigating numerous space problems over the years I have written the following scripts to ease the problem.
The First script is dfsort. All this script does is sort your filesystems into order of percentage space used. This immediately shows you where the problem is.
dfsort Script
#!/usr/bin/ksh
#
# Script: dfsort
# Aim: Show filesystems sorted by percentage full
#
#
# Start of main processing
#
SCRIPT=`$basename $0 `
PARMS="$*"
initialisation
showSpace
exit 0
Once the problem Filesystem has been identified, the fisrt method of attack is to determine the largest files within that filesystem. Use the script below finds. This script lists all the files within the filesystem in size order. I usually pipe the output through tail just to list the largest files, eg:
finds /usr | tail -10
Here is the finds script:
#!/usr/bin/ksh
#
# Script: finds
# Aim: List files in a filesystem by size
#
awk="/usr/bin/awk"
basename="/usr/bin/basename"
cut="/usr/bin/cut"
find="/usr/bin/find"
sort="/usr/bin/sort"
#
# Functions
#
checkParms()
{
FILELIST=""
for parm in $PARMS
do
if test "$parm" = "-r"
then
REVERSE="r"
else
check=`echo "$parm" | $cut -c1 `
if test "$check" != "-"
then
FILELIST="$FILELIST $parm"
fi
fi
done
return
}
listFiles()
{
$find $FILELIST -xdev -type f -ls |
$awk '{ print $7 ": " $0 }' |
$sort -t: +0 -1 -n$REVERSE |
$awk '{ printf "%7s %4s %10s %2s %-8s %-8s %10s %3s %2s %5s %s\n", $2,
$3, $4, $5, $6, $7, $8, $9, $10, $11, $12 }'
return
}
#
# Start of main processing
#
SCRIPT=`$basename $0 `
PARMS="$*"
checkParms
listFiles
exit 0
If this does not immediately highlight the cause of the problem, my next line of attack is to list the files in the filesystem sorted by modification time, in the hope that the files most recently changed are the cause of the problem. I use findt listed below.
Findt script
#!/usr/bin/ksh
#
# Script: finds
# Aim: List files in a filesystem by modification time
#
awk="/usr/bin/awk"
basename="/usr/bin/basename"
cut="/usr/bin/cut"
date="/usr/bin/date"
find="/usr/bin/find"
sed="/usr/bin/sed"
sort="/usr/bin/sort"
#
# Functions
#
checkParms()
{
FILELIST=""
for parm in $PARMS
do
if test "$parm" = "-r"
then
REVERSE="r"
else
check=`echo "$parm" | $cut -c1 `
if test "$check" != "-"
then
FILELIST="$FILELIST $parm"
fi
fi
done
return
}
if ( length($10) == 4 )
{
year = $10
hour = "00:00"
}
else
{
if ( month <= thismonth ) { year = thisyear }
if ( month > thismonth ) { year = lastyear }
hour = $10
}
print year "/" month "/" day, hour, $0
}
' |
$sort $REVERSE |
$cut -c17-
return
}
#
# Start of main processing
#
SCRIPT=`$basename $0 `
PARMS="$*"
showFiles
exit 0
Once you have discovered the cause of your space problem, it may be best to copy the offending file elsewhere and then clear down the offending file, ie:
cat /dev/null > /filename
This has the advantage of freeing the disk space immediately, which removing a file will not do if the file is open to a running process.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.