Saturday, 1 September 2012

bash script - move content from one directory to another

Here's a script that move content from one directory to another, as soon as soon some new files arrive in source directory.


#!/bin/bash
SOURCE="/home/ftp/dropzone"
DEST="/home/backup/ftp_files_storage"
if [ `find ${SOURCE} -type f` ]
then
        echo Files found in ${SOURCE}
        echo Moving files to ${DEST}
        find ${SOURCE} -type f -ls
        mv -f ${SOURCE}/* ${DEST}/
else
        echo ${SOURCE} is empty, nothing to do...
fi


and finally crontab entry to run script every minute:
* * * * * /usr/bin/movefiles.sh > /var/log/movefiles.log 2>&1