#!/bin/bash # call ./script.sh 03-2007 - to remove all March-2007 directories in 01-03-2007, 02-03-2007, 31-03-2007 format # you must have ncftp ftp client installed on BSD / Linux box # http://www.cyberciti.biz/tips/rotate-ftp-backup-using-a-shell-script.html BASE="/mysql" # base dir below that dd-mm-yyyy [ $# -eq 0 ] && exit 1 || : DELETE="$1" echo "Getting old directories..." ncftpls -u 'ftp-user-name' -p 'ftp-password' -x "-t" ftp://ftp.your-server.com${BASE} > /tmp/ftp.out LIST="$(grep ${DELETE} /tmp/ftp.out)" echo -n "Starting removal for ${DELETE}..." for dir in $LIST do rdir="${BASE}/${dir}" # echo "Processing ${dir}..." ncftp -L -u 'ftp-user-name' -p 'ftp-password' ftp.your-server.com <