Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $# != 1 ] ; then
- echo "Usage: sh $0 /path/to/sort/dir"
- exit 1;
- fi
- WORK_DIR=$1
- # sort all xml files by subdirs, named by date of file
- find -- $WORK_DIR -maxdepth 1 -type f -name "*.xml"|
- {
- while read filename
- do
- file_date=`date -r "$filename" "+%Y-%m-%d"`
- file_path=`dirname "$filename"`
- mkdir -p "$file_path/$file_date"
- mv "$filename" "$file_path/$file_date"
- done
- }
- # archive all dirs older 13 days (and remove after)
- find -- $WORK_DIR -maxdepth 1 -type d -mtime +13 \
- -exec tar -czf "{}.tar.gz" {} \; -exec rm -rf {} \;
- # delete tar archives older than a month
- find -- $WORK_DIR -maxdepth 1 -name "*.tar.gz" -mtime +30 -delete
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement