Per your bonus question, add the following line below the rsync
command in the shell script I provided below. I wrote this in the comment but I'll officially add it to my answer here:
find /auto/std2/nat2/B -name '*.zip' -exec sh -c 'unzip -d `dirname {}` {}' ';'
This will handle unzipping all the zip files that are copied via rsync
from folder /auto/std2/nat2/A
to /auto/std2/nat2/B
If you have rsync
installed why not just cron it and have rsync
manage the file mirroring?
Create script myrsyncscript.sh
Don't forget to make it executable: chmod 700 myrsyncscript.sh
#!/bin/sh
LOCKFILE=/tmp/.hiddenrsync.lock
if [ -e $LOCKFILE ]
then
echo "Lockfile exists, process currently running."
echo "If no processes exist, remove $LOCKFILE to clear."
echo "Exiting..."
# mailx -s "Rsync Lock - Lock File found" myemail@domain.com <<+
#Lockfile exists, process currently running.
#If no processes exist, remove $LOCKFILE to clear.
#+
exit
fi
touch $LOCKFILE
timestamp=`date +%Y-%m-%d::%H:%M:%s`
echo "Process started at: $timestamp" >> $LOCKFILE
## Run Rsync if no Lockfile
rsync -a --no-compress /auto/std1/nat1/A /auto/std2/nat2/B
echo "Task Finished, removing lock file now at `date +%Y-%m-%d::%H:%M:%s`"
rm $LOCKFILE
Options breakdown:
-a is for archive, which preserves ownership, permissions etc.
--no-compress as there's no lack of bandwidth between local devices
Additional options you might consider man rsync
:
--ignore-existing
skip updating files that exist on receiver
--update
This forces rsync to skip any files which exist on the destination and have a modified time that is newer than the source file. (If an existing destination file has a modification time equal to the source file’s, it will be updated if the sizes are different.)
Note that this does not affect the copying of symlinks or other special files. Also, a difference of file format between the sender and receiver is always considered to be important enough for an update, no matter what date is on the objects. In other words, if the source has a directory where the destination has a file, the transfer would occur regardless of the timestamps.
This option is a transfer rule, not an exclude, so it doesn’t affect the data that goes into the file-lists, and thus it doesn’t affect deletions. It just limits the files that the receiver requests to be transferred.
Add it to cron like so, and set the frequency to whatever you feel most comfortable with:
Open cron with crontab -e
and add the below:
### Every 5 minutes
*/5 * * * * /path/to/my/script/myrsyncscript.sh > /path/to/my/logfile 2>&1
# * * * * * command to execute
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
# │ │ │ └────────── month (1 - 12)
# │ │ └─────────────── day of month (1 - 31)
# │ └──────────────────── hour (0 - 23)
# └───────────────────────── min (0 - 59)
inotify
. Check this http://stackoverflow.com/questions/18692134/continuously-monitor-a-directory-in-linux-and-notify-when-a-new-file-is-availabl – jcbermu Feb 23 '15 at 16:26