Repository navigation
Expand file tree
/
Copy pathftpfilemon.sh
More file actions
68 lines (64 loc) · 1.41 KB
/
Copy pathftpfilemon.sh
File metadata and controls
68 lines (64 loc) · 1.41 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# Paul Pasika
# paul.pasika@proxibid.com
# 09/16/2011
#
# Monitors directories and rsync's them to the file share for common access.
#
### Configuration
###
###
###
targethost=targethost
LOG="/var/log/ftpfilemon"
PID="/var/run/ftpfilemon.sh.pid"
###
###
###
set -x
echo $$ > $PID
ps -ef | grep "bash" | grep "ftpfilemon" | grep -v `cat $PID` | awk '{print "kill "$2}' | sh
killall inotifywait
trap 'killall inotifywait' INT TERM EXIT
trap 'killall -g ftpfilemon.sh' INT TERM EXIT
function reset_counter
{
if (( $count > 20 ))
then
count=0
fi
}
for i in folder1 folder2 folder3 folder4
do
inotifywait -m -r --format '%w' /home/$i/ 2>/dev/null | while read j
do
echo $$ >> $PID
size=`du -s /home/$i | awk '{print $1}'`
while true
do
sleep .5
newsize=`du -s /home/$i | awk '{print $1}'`
if (( $size != $newsize))
then
size=$newsize
count=0
elif (( $size == $newsize))
then
((count++))
reset_counter
if (( $count == 20 )) && (( $size != 20 ))
then
count=0
date >> $LOG
rsync --stats -avz /home/$i $targethost:/data/ &>> $LOG
echo "`date` End of Transfer." >> $LOG
ssh root@$targethost "chown -R smbguest.smbguest -- /data/$i"
echo "`date` End of permission modifications." >> $LOG
#rm -rf /home/$i/* && echo "`date` Removed files in /home/$i/*" >> $LOG
continue 2
fi
fi
done
done &
done
wait