Created
November 13, 2013 09:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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