-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssync
More file actions
executable file
·67 lines (55 loc) · 1.19 KB
/
Copy pathssync
File metadata and controls
executable file
·67 lines (55 loc) · 1.19 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
#!/bin/bash
# usage
# ssync syncfile/ remotefile/ root@remote root@remote2
syncroot=`eval "echo $1"`
remoteroot=$2
shift 2
remotes="$@"
exit_script() {
echo "Exiting ssync"
trap - SIGINT SIGTERM
kill -- -$$
}
trap exit_script SIGINT SIGINT
if [ ! -e "$syncroot" ]
then
echo "error: local file ¬∃"
echo "exiting"
exit 1
fi
modified=`stat -c %Y $(find $syncroot -type f)`
function init() {
echo "copying ssh public key to remote"
for remote in $remotes
do
ssh-copy-id $remote
[ $? -ne 0 ] && echo "failed copying ssh key to $remote"
done
echo "finished init process"
}
function copyfolder() {
echo "begin sync cycle"
for remote in $remotes
do
echo "syncing to $remote:$remoteroot"
echo "$syncroot"
scp -r "$syncroot" "$remote:$remoteroot"
[ $? -ne 0 ] && echo "failed sycning to $remote:$remoteroot"
done
echo "finished syncing"
}
function checkChanged() {
modified_now=`stat -c %Y $(find $syncroot -type f)`
if [ "$modified" == "$modified_now" ]
then
return 0
fi
copyfolder
modified=$modified_now
}
init
while true
do
checkChanged
sleep 3
done