Skip to content

Instantly share code, notes, and snippets.

@palkan
Created November 13, 2013 09:59
Show Gist options
  • Save palkan/7446536 to your computer and use it in GitHub Desktop.
Save palkan/7446536 to your computer and use it in GitHub Desktop.
Script to delete directories older than 1 day within target directory. Path to target directory is stored in Erlang application's app.config file as {storage_dir, "path/to/dir"}. Pass path to config as the first argument.
#!/bin/bash
echo [$(date +"%Y-%m-%d %H:%M:%S")] Flush temporary files begins.
SOURCE="${BASH_SOURCE[0]}"
ROOT_DIR=$( dirname "${SOURCE}")
CONFIG=${1}
DIR=FALSE
if [ -f $CONFIG ]
then
while read line
do
echo $line | grep -q storage_dir
if [ $? == 0 ]; then
re="^\{storage_dir,\"([^\}]+)\"\}\.$"
[[ $line =~ $re ]] && var1="${BASH_REMATCH[1]}" && DIR=${var1}/
fi
done < $CONFIG
else
echo 'not_a_file'
exit 0
fi
find ${DIR} -mindepth 1 -maxdepth 1 -type d -mtime +1 -exec rm -R {} \;
echo [$(date +"%Y-%m-%d %H:%M:%S")] Flush complete.
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment