#!/bin/bash local_dir=/root/test remote_host="0.0.0.0" remote_dir=/root/test completed_dir=/root/completed alias rm="rm" cd $local_dir echo "STARTING TRANSFER FOR UGC-INTERNAL `date`" if [ -f $local_dir/.running ] then echo "Another processing is running, will exit" exit else touch $local_dir/.running fi # copy the file from the UGC-INTERNAL DMZ server to local box for i in `ssh root@$remote_host "find $remote_dir -type f -print -exec ls {} \;" `; do cd $local_dir scp root@$remote_host:${i} $local_dir echo "finished transferring files ${i} from UGC-INTERNAL DMZ server to localhost" done # remove files from the UGC-INTERNAL completed dir for t in `ssh root@$remote_host "find $remote_dir -type f -print -exec ls {} \;"`; do echo " Moving files ${t} to ${completed_dir}" ssh root@$remote_host "mv ${t} $completed_dir" done for r in `ssh root@$remote_host "find $completed_dir -print -mtime +30 -exec ls {} \;"`; do echo "Removing files ${r} from UGC-INTERNAL DMZ server" ssh root@$remote_host "rm ${r}" done rm $local_dir/.running echo "COMPLETED `date`" exit