Alex Rivera | Logout

Linux shell script for delete old files from ftp

Asked 2012-06-26T09:04:29.000
10

There is a problem - need to store the database backup on the FTP. On the FTP should not be more than 10 back-ups, ie, After you add backup to FTP should be removed, the oldest files to make the total number of files can not exceed 10 pieces. How can we implement such a removal from the ftp? I'm trying to write a script, but does not work delete:

x=1
ftp -vn $FTP_SERVER<<!
user $FTP_LOGIN $FTP_PASSWORD
binary
put $DUMP_FILE_NAME

for i in `ls -t` do
    if [ $x -le $keep ] then
        ((x++))
        continue
    fi
    delete $i
done

bye
EOF
</i>
Edit
Report

1 Answer

-5

Don't use FTP (for many reasons). However, if you do that in ssh, you get a tty, environment, and everything else. Also, if you want a file 10 days old to be deleted (and not one 10 calendar days stale) a simple find -mtime +10 -delete would replace that for loop. So:

ssh user@host 'find $DIR -mtime +10 -delete'

If you want FTP, look at NcFTP, if I recall correctly there were some pretty decent scripting capabilities there.

answered 2012-06-26T09:25:09.477

Your Answer