Create morethanxdays.sh

This commit is contained in:
Ankam Ravi Kumar
2019-01-01 16:27:35 +05:30
committed by GitHub
parent 1e49574337
commit 14c9f52449

14
morethanxdays.sh Normal file
View File

@ -0,0 +1,14 @@
#!/bin/bash
## Delete the Directories older than 2 days based on directory name validation
## Refer YouTube Link for Explanation https://youtu.be/1Sh6PWcgXAA
ls -ltr /fullbackup/archive/ | awk '{print $9}' > /scripts/dirs
for i in `cat /scripts/dirs`; do
STARTTIME=$(date +%s -d"$i 00:00:00")
ENDTIME=$(date +%s)
echo $((ENDTIME-STARTTIME)) | awk '{print int($1/60)}' > /scripts/value
COUNT=`cat /scripts/value`
if [ $COUNT -gt 2880 ]; then
echo "Directories are older than 2days $i" >> /scripts/joblog
rm -rf /fullbackup/archive/$i
fi
done