I have a script that uploaded a compressed file to an ftp, it is the code that I show below.
This code works correctly, but I would like to adapt it so that once the file is uploaded, it deletes ftp files older than a week.
#!/bin/sh
HOST='xxx'
USER='xxx'
PASSWD='xxx'
DAY=`date +"%d%m%Y_%H%M"`
cd /temp
rm -fr backup
mkdir backup
cd backup
export GZIP=-9
tar -czvf $DAY-backup.tar.gz --exclude="*/node_modules/*" /var/www/html/cars
FILE=$DAY-backup.tar.gz
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
binary
put $FILE
quit
END_SCRIPT
exit 0
2
Answers
One option is to use a find command to catch file older than 7 days and delete it.
So it give something like this :
You can add this line in your script
If you want to test first remove replace the exec part by print to display the files catched :
You can try this solution: