Добрый день.
Такой скрипт:
--
#!/bin/bash
USERNAME=""
PASSWORD=""
SERVER=""
BACKUPDATE=`date +%Y-%m-%d`;
OLDDATE=`date +%Y-%m-%d --date='5 days ago'`;
FROM="/root/backup/_${BACKUPDATE}/"
TO="/_dump/_${BACKUPDATE}/"
OLDDIR="/_dump/_${OLDDATE}/"
FTP="$(which ftp)"$FTP -n $SERVER <<EOT
quote USER $USERNAME
quote PASS $PASSWORD
mkdir ${TO}
prompt
lcd ${FROM}
cd ${TO}
mput *.gz
cd ${OLDDIR}
rm ${OLDDIR}
rmdir ${OLDDIR}
quit
EOT
--Ответ
на rm/rmdir - Directory not empty
--ignore-fail-on-non-empty - No such file or directoryКак удалить мне папку ${OLDDIR}?
> Как удалить мне папку ${OLDDIR}?# ncftpget -u username -p password -R -DD ftp://${SERVER}/${OLDDIR}
# lftp -u username,password -e "mirror --reverse --delete ${OLDDIR}" ${SERVER}
----
На гуглю вас фейс-контроль не пускает?! :)
#!/bin/bash# Script for retrieving all files on a an ftp server then deleting them.
#
# Requires ncftp and stock ftp client.
#
# We have to do some funkyness since there is no easy way of recursively deleting
# remote directories. We use ncftp to download all files and delete them on successfull
# download. This ,however, leaves empty directories. So we download the empty directory
# tree to FSTREEDIR to list all directories to delete(we can't trust the download directory
# because other directories may exist there). Those directories are then passed to the
# usual ftp client to delete.# @todo - store credentials in a file
FTPSERVER=10.0.1.150
DOWNLOADDIR=/tmp/dl
FSTREEDIR=$DOWNLOADDIR/fstree
USERNAME=bart
PASSWORD=dude
DELETEREMOTEFILES=1
if [ $DELETEREMOTEFILES -eq 1 ]
then
DELFILESFLAG="-DD"
else
DELFILESFLAG=""
fiecho "Downloading Reports...
"cd $DOWNLOADDIR
ncftpget -u $USERNAME -p $PASSWORD -R $DELFILESFLAG ftp://$FTPSERVER
# Delete Files after download
if [ $DELETEREMOTEFILES -eq 1 ]
then
echo "Deleting Remote Reports...
"
RMSTRING=""
# if fstree dir exists empty it and recreate it
if [ ! -d "$FSTREEDIR" ]; then
mkdir $FSTREEDIR
else
rm -rf $FSTREEDIR/*
fi# Copy remote directory structure to FSTREEDIR
cd $FSTREEDIR
ncftpget -u $USERNAME -p $PASSWORD -R $DELFILESFLAG ftp://$FTPSERVER# Generate list of directories to delete
for D in `find $FSTREEDIR -type d| sort -r`
do
if [ ! "$D" = "$FSTREEDIR" ]; then
RMSTRING="$RMSTRING
rmdir ${D#$FSTREEDIR/}"
fi
done# Delete remote file structure
ftp -i -n <<EOF
open $FTPSERVER
user $USERNAME $PASSWORD
$RMSTRING
EOF# delete old FSTREEDIR
rm -rf $FSTREEDIRfi