-
Notifications
You must be signed in to change notification settings - Fork 1
/
dtransfer.sh
executable file
·91 lines (82 loc) · 2.5 KB
/
dtransfer.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
#
# Distributor shell script to transfer any additional cached data
# Given number of .dat files and remote destinations
# Copy each file to each of the destinations
# dtransfer.sh - "distributed transfer shell".
# 2015 Victoria Rudakova, [email protected]
# ARGUMENTS PARSING#{{{
# ================
# input arguments form (must be at least 6 args):
# login, remote_destination, n_cachef, path_cache, cache_var, {ipaddrs}
# The .dat files have the format: `path_cache/cache_var{i}.dat` for i=[1..n_cachef*n_ipaddrs]
# `n_cachef` stands for number of files to transfer per one remote
args=("$@")
printf "\nNumber of arguments passed: %d\n" $#
nargs=$#
if [ $nargs -lt 6 ]; then
echo "ERROR: Number of passed arguments is smaller than required minimum (6)"
exit 1
fi
nservs=$((nargs-5))
printf "Number of servers: %d\n" $nservs
LOGIN=${args[0]}
printf "The login parameter: %s\n" $LOGIN
PATH_REM=${args[1]}
printf "The remote working directory: %s\n" $PATH_REM
ncache=${args[2]}
printf "Number of .dat file to copy for EACH remote: %d\n" $ncache
nfiles=$(($nservs*$ncache))
printf "Total number of .dat files: %d\n" $nfiles
#rem_check=$(($nservs%$ncache)) # make sure the remainder is 0
#if [ $rem_check -ne 0 ]; then
# printf "ERROR: number of files to transfer must be the same for all the remotes\n"
# exit 1
#fi
PATH_CACHE=${args[3]}
CACHE=${args[4]}
printf "The cacned variable has following name format: %s\n" "$PATH_CACHE$CACHE.dat"
i=5
while true; do
IPADDRS[$((i-5))]=${args[$i]}
i=$((i+1))
nservs=$(($nservs-1))
if (( nservs <= 0 )); then
break
fi
done
printf "\nIP addresses extracted:\n"
echo ${IPADDRS[@]}
j=1
i=0
while true; do
test -e $PATH_CACHE$CACHE$j.dat
if [ $? -ne 0 ]; then
printf "ERROR: no such file: %s\n" $PATH_CACHE$CACHE$j.dat
exit 1
fi
CFILES[$i]="$CACHE$j.dat"
i=$((i+1))
j=$((j+1))
nfiles=$(($nfiles-1))
if (( nfiles <= 0 )); then
break
fi
done
printf "\nVariables-to-load extracted:\n"
echo $PATH_CACHE${CFILES[@]} #}}}
# CONNECT TO REMOTES, SCP FILES#{{{
# ================
i=0
printf "\nFile transfer\n"
for IPA in ${IPADDRS[@]}; do
ssh $LOGIN@$IPA "mkdir -p $PATH_REM" # create working directory, if necessary
ssh $LOGIN@$IPA "rm -f $PATH_REM/*.dat" # clear the working directory from any previous data
for (( j = 0; j < $ncache ; j++ )); do
idx=$(($i*$ncache+$j))
scp -c arcfour $PATH_CACHE${CFILES[$idx]} $LOGIN@$IPA:$PATH_REM
printf "scp returned %i\n" $?
done
i=$((i+1))
done #}}}
echo "Distributed transfer of .dat files done"