#!/bin/csh -f

# space_left version 1.1

# This simple script written by Joseph Traub (jtraub@cs.cmu.edu)
# Feel free to use it, hack it, have sex with it, or whatever.
# Author disclaims any responsibility whatsoever for any acts performed
# with this script or any derivitive thereof.

# Set this to point to the top level of your FSP export directory
set FSP_HOME = /usr/fsp/data

# Set this to point to your log directory.  If you do not want to keep a log
# from this script, set the LOG_DIR to be /dev/null
set LOG_DIR = /usr/fsp/logs

# grab the space available off the listed device.. This assumes that all
# df on unix output in the same format.
set space = `df $FSP_HOME | awk '{print $4}' | tail -1`
set space_left = 0

#remove any old space_left trackers.
\rm -rf ${FSP_HOME}/SPACE*  >& /dev/null

# compute the number of meg avail
@ space_left = $space / 1024

if ($space_left == 0) then
  # less than one meg available
  touch $FSP_HOME/SPACE_LEFT__${space}_K
  echo "["`date`"]" $space K available >> $LOG_DIR/space_left.log
else
  # at least one meg available
  touch $FSP_HOME/SPACE_LEFT__${space_left}_MEG
  echo "["`date`"]" $space_left Meg available >> $LOG_DIR/space_left.log
endif

exit 0
