#! /bin/sh
# Remove unused LTSP swap files

[ -f /etc/ltsp/nbdswapd.conf ] && . /etc/ltsp/nbdswapd.conf
[ "$SWAPDIR" ] || SWAPDIR=/tmp/nbd-swap//

cd $SWAPDIR || exit 1
for ip in `ls * 2>/dev/null`
do
   netstat -natup 2>/dev/null | grep ${ip}: >/dev/null && touch ${ip}
   ping -c 1 -w 10 ${ip} &> /dev/null && touch ${ip}
done

find $SWAPDIR -mtime +2 -exec rm {} \;

exit 0
