Skip to main content

Posts

Showing posts from July, 2011

How to mirror/sync a remote ftp folder with a local folder

lftp is one of the best command line utilities currently available for working with ftp servers, One of its useful features is mirroring which is suitable for backup purposes and very useful for slow connections. In this article i'm going to show you how to use this utility to backup and mirror your files a ftp server.

Simple Usage

The following script mirros your local folder to a remote ftp server, it only updates the changes you've made since the last execution so only the first time requires lots of bandwidth :

#!/bin/bash
HOST='mysite.com'
USER='myuser'
PASS='myuser'
TARGETFOLDER='/new'
SOURCEFOLDER='/home/myuser/backups'

lftp -f "
open $HOST
user $USER $PASS
lcd $SOURCEFOLDER
mirror --reverse --delete --verbose $SOURCEFOLDER $TARGETFOLDER
bye
"
You can save it as upload.sh and execute it using the following command :

bash upload.sh
Advanced Usage

lftp offers many parameters, here i'll explain some of the most useful o…

Send mail bash script

Sample Shell Script

Here is what you need to put in a shell script:

#!/bin/bash
# script to send simple email
# email subject
SUBJECT="SET-EMAIL-SUBJECT"
# Email To ?
EMAIL="admin@somewhere.com"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE