-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautosync
executable file
·61 lines (41 loc) · 1.15 KB
/
autosync
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
#!/bin/ksh
##Daniel Molina
##Sync host list
HORA=+%Y-%m-%d--%H:%M:%S
LISTA=$HOME/list
TEMPORAL=$HOME/temp
DESTINO=192.168.150.136
ACTIVE=0
LUSER=dmolinao
##Captura de salida
trap force_exit SIGINT
force_exit(){
echo
echo "Exiting..."
rm -f $HOME/.ACTIVO
rm -f $TEMPORAL
exit 3
}
ssh -i $HOME/.ssh/id_rsa ${LUSER}@${DESTINO} ls $HOME/.ACTIVO > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "ShitScript is active at $DESTINO"
exit 1
fi
echo $$ > $HOME/.ACTIVO
test -f $HOME/.ACTIVO > /dev/null 2>&1
ACTIVE=$?
while [ $ACTIVE -eq 0 ]; do
ssh -i $HOME/.ssh/id_rsa ${LUSER}@${DESTINO} ls $HOME/list > /dev/null 2>&1
cat $HOME/.ssh/known_hosts | cut -d "," -f1 | cut -d " " -f1 | uniq -u |sort >> $TEMPORAL
ssh -i $HOME/.ssh/id_rsa ${LUSER}@${DESTINO} cat $HOME/.ssh/known_hosts | cut -d "," -f1 | cut -d " " -f1 | uniq -u |sort >> $TEMPORAL
sort -u $TEMPORAL > $LISTA
rm -f $TEMPORAL
echo "#Last update $(date $HORA) done in $(hostname)" >> $LISTA
scp -i $LISTA
scp -i $HOME/.ssh/id_rsa $LISTA ${LUSER}@${DESTINO}: > /dev/null
sleep 600
ls .ACTIVO > /dev/null 2>&1
ACTIVE=$?
done
rm -f .ACTIVO
exit