Created
November 15, 2017 15:11
-
-
Save Shagshag/d742916d971b228386bca35f8d0ee264 to your computer and use it in GitHub Desktop.
Delete files older than X days on FTP. use curlftpfs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ftpuser="x" | |
ftppass="x" | |
ftpsite="x" | |
ndays=10 | |
# https://stackoverflow.com/a/34676160/2530962 | |
# the directory of the script | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
# the temp directory used, within $DIR | |
# omit the -p parameter to create a temporal directory in the default location | |
WORK_DIR=`mktemp -d -p "$DIR"` | |
# check if tmp dir was created | |
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then | |
echo "Could not create temp dir" | |
exit 1 | |
fi | |
# deletes the temp directory | |
function cleanup { | |
rm -rf "$WORK_DIR" | |
echo "Deleted temp working directory $WORK_DIR" | |
} | |
# register the cleanup function to be called on the EXIT signal | |
trap cleanup EXIT | |
# implementation of script starts here | |
curlftpfs ftp://$ftpsite -o user="$ftpuser:$ftppass" $WORK_DIR | |
find $WORK_DIR/* -mtime +$ndays -delete | |
fusermount -u $WORK_DIR/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment