mirror of
https://github.com/techarkit/shell-scripting-tutorial.git
synced 2025-07-25 01:28:51 +00:00
Create morethanxdays.sh
This commit is contained in:
14
morethanxdays.sh
Normal file
14
morethanxdays.sh
Normal 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
|
Reference in New Issue
Block a user