#!/bin/bash

source /gpfs/wizard/flight/production/installed/set_pam_env.sh > /dev/null 2>&1;

if [ "$PAM_BIN" == "" ]; then exit; fi

export PRODDIR=/gpfs/wizard/flight/production/

export WRKDIR=$PRODDIR/deamons/wrkdir/

export MAIL=Emiliano.Mocchiutti@ts.infn.it

#export CCMAIL=Emiliano.Mocchiutti@ts.infn.it
export CCMAIL=boezio@ts.infn.it

echo "3601" > $WRKDIR/dskspc.step 

TIME=`tail -1 $WRKDIR/dskspc.step`;

while [ $TIME -gt 0 ]; do

C=0;

for word in `/bin/df /gpfs/wizard/`; do 

	let C=$C+1; 

	if [ $C -eq 11 ]; then 

		GB=`echo $word`; 

	fi; 

done; 

#echo $GB

if [ "$GB" -lt 5000000 ]; then

	DF=`df `

	echo "DEAMONS STOPPED: $DF" | mail -s "WARNING: NO SPACE LEFT IN /gpfs/wizard/" -c $CCMAIL $MAIL

	for file in `ls $WRKDIR/*.step`; do

	    echo "-1" > $file;
#	    echo $file

	done;

#else 

#	echo "a lot of space"

fi;

#exit

sleep $TIME;

TIME=`tail -1 $WRKDIR/dskspc.step`;

done;
