-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpurge_exchanger.sh
More file actions
14 lines (10 loc) · 845 Bytes
/
purge_exchanger.sh
File metadata and controls
14 lines (10 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/sh
# This script for clear shared folder in 2 steps
# Step 1: Move files that does not created and not modified since last XX days to subfolder _XX_day_automatic_clean
# Step 2: If moved files not modified in XX days it will be deleted
days=21
src=/share/public/exchange
# move files to trash
eval "find \"$src/\" -not -path \"$src/_${days}_day_automatic_clean/*\" -a -type f -a -not -newerBt \"$days days ago\" -a -mtime +$days -a -ctime +$days -print0 | sed -z -e \"s|^$src/||\" | xargs -0 -I {} sh -c 'file=\"{}\"; mkdir -p \"$src/_${days}_day_automatic_clean/\${file%/*}\"; mv \"$src/\$file\" \"$src/_${days}_day_automatic_clean/\$file\"'; touch \"$src/_${days}_day_automatic_clean/$file\""
# purge trash
find "$src/_${days}_day_automatic_clean" -type f -a -not -newerBt "$days days ago" -a -mtime +$days -a -ctime +$days -delete