-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrsync-src-dst.sh
More file actions
executable file
·47 lines (36 loc) · 1.08 KB
/
rsync-src-dst.sh
File metadata and controls
executable file
·47 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /bin/bash
# script will rsync files from SRC to DST directory. SRC can be a symbolic link
# to a local folder, while DST can be a remotely mounted filesystem.
#
# add script to cron to run every x minutes. Before running it will check if
# it is already running, and exit if it is still running.
PGM=`basename $0 .sh`
LOG=~/log/${PGM}.log
PID=/tmp/${PGM}.pid
SRC=/var/src
DST=/var/dst
# check to see if old instance still running
if [ -r ${PID} ] ; then
myID=`cat ${PID}`
$(kill -0 $myID)
if [ $? == 0 ] ; then
echo "${PGM}: `date` `cat ${PID}` still running" >> ${LOG}
exit
fi
$(rm ${PID})
fi
# create PID file
echo $$ > ${PID}
echo "==================================================" >> ${LOG}
echo "${PGM} `date` starting $$" >> ${LOG}
src=$(mount -l -t cifs | grep -c $SRC)
dst=$(mount -l -t cifs | grep -c $DST)
if [ $src -eq 1 ] && [ $dst -eq 1 ]
then
rsync -arv $SRC $DST >> ${LOG}
fi
echo "${PGM} `date` complete" >> ${LOG}
# remove PID file
rm -fv ${PID} >> ${LOG}
echo "--------------------------------------------------" >> ${LOG}
exit