Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code review 1

Status
Not open for further replies.

yerra

IS-IT--Management
Jan 6, 2005
11
FR
I am writing a script to check the no of logs a directory can hold and % of disk space available. If directory can hold only 50 logs more or disk % available is only 80% then Alert the admin. Though the below code works, I was looking at a better script which might elimnate calling df -k multiple times to get different fields for comparison. This would make a concise code.


ARCAREA=/archives
DISKSPACE=`df -k $ARCAREA |grep -v "Available" |awk '{print $4}'`
TOTALLOG=`expr "$DISKSPACE" \* 1024 / "$LOGSIZE"`
PERCSPACE=`df -k $ARCAREA | grep -v Capacity | sed "s/%//g" |awk '{print $5}'`
echo "The Primary Archive Destination : $ARCAREA$"
echo "Max Size Of Each Archive Logs : $LOGSIZE$ bytes"
echo "Number Of Logs That Can Fit In : $TOTALLOG}"
echo "Available Perc Of Disk Space : $PERCSPACE"
if [ $PERCSPACE -gt 80 -o $TOTALLOG -lt 50 ] ; then
echo " Problem Available"
else
echo " NoProblem Available"
fi
 
What OS are you using, because the output of df on my linux box would not work with your script. Post what your df output looks like.
 
I am using Dec AlPha V5.1.
The query is
ARCAREA=/archives
ARCLOG=ARCHIVELOG,78643200
LOGSIZE=`echo $ARCLOG |awk -F, '{print $2}'`
DISKSPACE=`df -k $ARCAREA |grep -v "Available" |awk '{print $4}'`
TOTALLOG=`expr "$DISKSPACE" \* 1024 / "$LOGSIZE"`
PERCSPACE=`df -k $ARCAREA | grep -v Capacity | sed "s/%//g" |awk '{print $5}'`
echo "The Primary Archive Destination : $ARCAREA"
echo "Max Size Of Each Archive Logs : $LOGSIZE bytes"
echo "Number Of Logs That Can Fit In : $TOTALLOG"
echo "Available Perc Of Disk Space : $PERCSPACE"
if [ $PERCSPACE -gt 80 -o $TOTALLOG -lt 50 ] ; then
echo " Problem Available"
else
echo " NoProblem Available"
fi

The O/p is
The Primary Archive Destination : /archives
Max Size Of Each Archive Logs : 78643200 bytes
Number Of Logs That Can Fit In : 462
Available Perc Of Disk Space : 0
NoProblem Available


The o/p of df -k is
root_domain#root 2075344 303830 1764384 15% /
/proc 0 0 0 100% /proc
usr_domain#usr 2097192 683996 1396272 33% /usr
var_domain#var 2097192 82206 2007760 4% /var
ssbora1#u01 6145872 2095225 4041104 35% /u01
orassb2#u02 13459512 50600 13404064 1% /u02
orassb3#u03 12328224 56 12323336 1% /u03
orassb4#u04 12359760 1299937 11053968 11% /u04
ora_ssb8#u08 35566000 24481 35534800 1% /u08
ora_ssb9#u09 35566000 20772031 14786360 59% /u09
archives#archives 35553280 24 35547048 0% /archives
 
Save the output in a temporary file perhaps.

Code:
ARCAREA=/archives
df -k $ARCAREA > /tmp/check$$
DISKSPACE=`grep -v "Available" /tmp/check$$ | 
    awk '{print $4}'`
TOTALLOG=`expr "$DISKSPACE" \* 1024 / "$LOGSIZE"`
PERCSPACE=`grep -v Capacity /tmp/check$$ | 
    sed "s/%//g" |
    awk  '{print $5}'`
echo "The Primary Archive Destination   :       $ARCAREA$"
echo "Max Size Of Each Archive Logs     :       $LOGSIZE$ bytes"
echo "Number Of Logs That Can Fit In    :       $TOTALLOG}"
echo "Available Perc Of Disk Space      :       $PERCSPACE"
if [ $PERCSPACE -gt 80  -o $TOTALLOG -lt 50 ] ; then
echo " Problem Available"
else
echo " NoProblem Available"
fi
rm /tmp/check$$

--
 
In all honesty, df -k is not an expensive call, all the totals for disk usage are stored in the partition's metadata. I wouldn't worry that much about multiple calls.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top