#!/bin/sh timeref="/data/lastclean" if [ -z "$RESULTDIR" ]; then echo "RESULTDIR is undefined! skipping cleanup.." exit 1 fi if [ -f "$timeref" ]; then files="$(find "$RESULTDIR" -mindepth 1 \! -newer "$timeref")" echo "$files" | while read path; do rm -rf "$path" done if [ -z "$files" ]; then filecount=0 else filecount=$(echo "$files" | wc -l) fi echo "[ $(date +%T) ] Removed $filecount old files!" fi touch "$timeref"