Rotate FTP Backup Using a Shell Script

Posted on in Categories Backup, Howto, Linux, RedHat/Fedora Linux, Shell scripting, Tips, Ubuntu Linux, UNIX last updated January 20, 2008

I’ve already written about rotating sftp / ssh backup shell script to remove directories (old backup files). However, a few of our readers would like to know more about removing old backup directories using ftp. As usual, you need accurate date and time on local system and remote backup directory must be in dd-mm-yyyy or mm-dd-yyyy format. For example daily mysql backup should be stored in /mysql/dd-mm-yyyy format.

Sample Shell Script

Here is a simple and dirty shell script to remove old backups ( download link ):

# call ./ 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
BASE="/mysql" # base dir below that dd-mm-yyyy
[ $# -eq 0 ] && exit 1 || :
echo "Getting old directories..."
ncftpls -u 'ftp-user-name' -p 'ftp-password' -x "-t"${BASE} > /tmp/ftp.out
LIST="$(grep ${DELETE} /tmp/ftp.out)"
echo -n "Starting removal for ${DELETE}..."
for dir in $LIST
# echo "Processing ${dir}..."
 ncftp -L -u 'ftp-user-name' -p 'ftp-password' <<EOF
 cd $rdir
 rm *
 rmdir $rdir

Run the script as follows to remove all backup for Dec-2007, enter:
$ ./ 12-2007

Related: Generate backup ftp script using php based wizard

Sendmail is only accepting connections from localhost ( IP)

Posted on in Categories FAQ, Troubleshooting last updated December 18, 2007

Q. My sendmail service is running under Linux and whenever I try to telnet it from other LAN IP, it gives connection refuse error. If I connect it from localhost it accept connection. I can only send mail from my server only. How do I force sendmail to accept mail from other hosts/LAN ips?

A. For security reason sendmail is by default configured to accept connection from local system ( This should avoid open mail relay problem.

To allow connections from ALL hosts/LAN IPs open file (login as the root):

# vi /etc/mail/

Look for line that read as follows:

DAEMON_OPTIONS(`Port=smtp,Addr=, Name=MTA’)dnl

Comment or remove above line and insert new line that read as follows:


Above line will force to accept connection from any host. Save the file. Regenerate sendmail configuration file using m4:

# m4 /etc/mail/ > /etc/mail/

Restart sendmail service :

# /etc/init.d/sendmail restart

Caution: You should configure firewall and other Sendmail Anti-Spam configuration control to avoid problems.

See also: