2008年5月8日 星期四

How to synchronize FTP contents by light way

Our company have many contents from Partner's ftp sites need to keep synchronizing in time, and send notification email to guys who need to know latest updates.
I used following method to let this work by automatic. It only get changed files when remote FTP contents were changed.
1) Get a perl script(ftpsync.pl) writted by Christoph Lechleitner ( ftpsync at ibcl.at )
http://ftpsync.sourceforge.net/
2) Add some output information to a file which will be used to send information
3) Install esmtp package into Linux System
4) Add a script into cron job at AM 2:00(Taiwan timezone)

#!/bin/bash
/root/ftpsync.pl -g ftpserver=xx ftpuser=xx ftppasswd=xx ftpdir="/" /root/ftp
sleep 10
mount -t cifs -o username=xx,password=xx,codepage=cp950 //xx/SEShare /root/seshare
sleep 10
rsync -a /root/ftp/. "/root/seshare/"
sleep 10
cd /
umount /root/seshare
#Send notification email to cbu group
cd /root
domail=`cat /root/ttt.txt wc -c`
to='To: abc@c.d.e.f'
from='From: xyz@c.d.e.f'
subject='Subject: [News - xx] New update file in BulletinBoard'
echo $to > /root/mail.txt
echo $from >> /root/mail.txt
echo $subject >> /root/mail.txt
echo >> /root/mail.txt
cat /root/ttt.txt >> /root/mail.txt
if [ "$domail" = "0" ]; then echo "Don't send email if empty update"
else
cat /root/mail.txt | esmtp abc@c.d.e.f -f xyz@c.d.e.f
fi

1 則留言:

匿名 提到...

Keep up this fine content, added to my personal internet explorer feed.