Tuesday, March 22, 2011

 

Script To Monitor Disk Space Use

Here is a simple script to monitor disk space usage in real time. I put this together because I am frequently frustrated to find that Windows (often during updates) or some other badly organized program has decided to use more disk space than my lowly laptop can provide. The Linux "df -h ." provides the necessary information, and it is a simple matter to put this command into a loop. For additional convenience, the script handles reporting to the screen with only carriage returns (no line feeds) so you won't chew up the windows complete contents with a long list of disk space information, no matter how long you run the script. Here is the typical output:

ctrl-c to stop
Filesystem Size Used Avail Use% Mounted on Time
C:/cygwin 75G 71G 4.3G 95% / Tue Mar 22 15:28:29 PDT 2011

and the script itself:

#!/bin/sh

#monitor disk space usage

HEADING=`df -h . | head -1`
echo "ctrl-c to stop"
echo "$HEADING Time "

while true
do
CURRENT=`df -h . | tail -1`
CURRENT=$CURRENT" "`date`
echo -e -n "$CURRENT\r"
sleep 3
done

Now I can keep an eye on what Windows is subjecting me to, in approximately real time.
Comments: Post a Comment



<< Home
Newer Posts Older Posts