I have a directory /backup that contains other directories with daily backups in them. Those directories are sorted by name and date (BACKUP_date). The few lines of bash script which i had been using before worked until the beginning of a new month and stopped due to some unforeseen situations. this was what i used previously
#!/bin/bash
ndate=$(date "+%Y%m%d")
ndays=8
ddate=$((ndate-ndays))
cd /backup || exit
rm -rf BACKUP_$ddate
How can i modify this to be much more intelligent.
Best Answer
If you echo the values, it is obvious what goes wrong:
There is no 98th day in August.
So, a beter way would be to let
date
do the calculation: