-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdateRemote.sh
executable file
·74 lines (61 loc) · 1.75 KB
/
updateRemote.sh
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
69
70
71
72
73
74
#! /bin/bash
#Global Variables
DIR=`dirname $0`
input="$DIR/data/remoteAddresses.txt"
DEFAULT_REMOTE_PATH="Desktop/RemoteGamesFiles"
REMOTE_SCRIPTS_PATH="$DIR/RemoteSubScritps"
TEAMS_PATH=`head -n 1 $DIR/data/path.txt`
declare -i count
declare -i runFlag
#methods
compress() {
#compressing and packaging all the files for faster transmit
echo "Compressing files."
tar -czf $DIR/transfer.tar.gz $TEAMS_PATH $REMOTE_SCRIPTS_PATH/remoteRun.sh\
$DIR/data/path.txt $DIR/data/masterAddress.txt $REMOTE_SCRIPTS_PATH/kill.sh
echo "Files compressed."
}
update() {
#reading remote server addresses and copying and then extracting the package
#created above and then putting files in the right order
while IFS= read -r line
do
count=0
for word in $line
do
W[count]=$word
count+=1
done
if [ $count -eq 3 ]
then
server=${W[0]}
remotePath=${W[2]}
elif [ $count -eq 2 ]
then
server=${W[0]}
declare -i idx=`expr index ${W[0]} '@'`
user=${W[0]:0:idx-1}
remotePath="/home/$user/$DEFAULT_REMOTE_PATH"
fi
if [[ $count -gt 1 ]] && [[ $count -lt 4 ]] && [[ ${server:0:1} != "#" ]]
then
ssh $server mkdir -p $remotePath </dev/null
scp -rC $DIR/transfer.tar.gz "$server:$remotePath" >/tmp/tmp_scp_log.txt </dev/null
ssh $server tar -xzf $remotePath/transfer.tar.gz -C $remotePath/ </dev/null
ssh $server mv $remotePath/RemoteSubScritps/* $remotePath/ </dev/null
ssh $server rm -r $remotePath/RemoteSubScritps </dev/null
ssh $server rm $remotePath/transfer.tar.gz </dev/null
echo "$server -> Done."
fi
done < $input
wait
}
#main method
main() {
compress
update
#removing the package created above
rm $DIR/transfer.tar.gz
}
#
main