Simple script to clean /tmp and other dirs
Tuesday Apr 9 11:11:47 2013
I wrote this simple script to clean /tmp on a monthly basis
but I soon added other directories.
#!/bin/sh
set -e
# Script to clean directories. The ls -A means that it does not
# list . & ..
#
# BIG FAT WARNING: rm -rf is potentially dangerous. Use this at
# your own risk!
# Directories to clean.
TRASH="/home/chals/.local/share/Trash/files" # Trash in Xfce
DIR_TO_CLEAN1="/home/chals/tmp"
DIR_TO_CLEAN2="/tmp"
# Where to write the log file.
LOG_FILE="/home/chals/clean.log"
# Let's do it!
for DIR in ${TRASH} ${DIR_TO_CLEAN1} ${DIR_TO_CLEAN2}
do
if [ "$(ls -A ${DIR})" ]
then
rm -rf ${DIR}/* && rm -rf ${DIR}/.??* > /dev/null 2>&1 # Remove
echo "$(date) Cleaning ${DIR} :) " >> ${LOG_FILE}
else
echo "$(date) Nothing to be done, ${DIR} is empty :( " >> ${LOG
fi
done