Skip to content

Instantly share code, notes, and snippets.

@jollyroger
Created February 5, 2010 13:27
Show Gist options
  • Save jollyroger/295776 to your computer and use it in GitHub Desktop.
Save jollyroger/295776 to your computer and use it in GitHub Desktop.
Cean incoming cronjob
#!/bin/sh
RMFILE_LOG=`mktemp`
RMFILE_ERR=`mktemp`
RMDIR_LOG=`mktemp`
RMDIR_ERR=`mktemp`
find ~ftp/incoming -mindepth 1 -mount -type f -atime +7 -exec rm -vf {} \; >$RMFILE_LOG 2>$RMFILE_ERR
find ~ftp/incoming -depth -mindepth 1 -mount -type d -empty -exec rmdir -v {} \; >$RMDIR_LOG 2>$RMDIR_ERR
echo "Cleaning FTP incoming directory:"
FILE_ERRORS=`wc -l < $RMFILE_ERR`
echo "`wc -l <$RMFILE_LOG` file(s) to delete, $FILE_ERRORS error(s)"
DIR_ERRORS=`wc -l <$RMDIR_ERR`
echo "`wc -l <$RMDIR_LOG` empty dir(s) to delete, $DIR_ERRORS error(s)"
if [ "$FILE_ERRORS" -gt 0 ] ; then
echo
echo "File deletion errors:"
cat $RMFILE_ERR
fi
if [ "$DIR_ERRORS" -gt 0 ] ; then
echo
echo "Directory deletion errors:"
cat $RMDIR_ERR
fi
rm $RMFILE_LOG $RMFILE_ERR $RMDIR_LOG $RMDIR_ERR
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment