-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdtest.sh
More file actions
executable file
·63 lines (54 loc) · 1.84 KB
/
dtest.sh
File metadata and controls
executable file
·63 lines (54 loc) · 1.84 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
#!/bin/bash
#
# A script to test accessibility to spicified IP addresses
# Tests if the private key is added (ssh-add), if not, throws connectivity error
# Creates a workfolder on each of the remotes
# If the workfolder already exists, it clears all the previous data stored in there
# dtest.sh - distributed tester
# 2015, Victoria Rudakova, vicrucann@gmail.com
TSTART=$(date +%s.%N) # time tracking
printf "Testing if SSH connection can be set up successfully\n"
args=("$@")
nargs=$#
printf "Number of input args is %i\n" $nargs
if [ $nargs -lt 3 ]; then
printf "ERROR: There must be at least two passed parameters (login, path_rem and IP address)\n"
exit 1
fi
LOGIN=${args[0]}
printf "Login is %s\n" $LOGIN
PATH_REM=${args[1]}
printf "Remote directory path is %s\n" $PATH_REM
nservs=$((nargs-2))
printf "Number of servers is %i\n" $nservs
i=2
while true; do
IPADDRS[$((i-2))]=${args[$i]}
i=$((i+1))
nservs=$((nservs-1))
if (( nservs <= 0 )); then
break
fi
done
printf "Done reading the IP addresses\n"
for IPA in ${IPADDRS[@]}; do
printf "Trying to SSH to server %s\n" $IPA
ssh -q $LOGIN@$IPA exit
status=$?
if [ $status -eq 255 ]; then
printf "ERROR: server %s is not accessible, check connectivity and private key setup\n" $IPA
exit 1
fi
printf " - success\n"
ssh $LOGIN@$IPA "mkdir -p $PATH_REM" # create working directory, if necessary
status=$?
if [ $status -eq 255 ]; then
printf "ERROR: server %s - the working directory could not be created, check the rights to run mkdir\n" $IPA
fi
ssh $LOGIN@$IPA "rm -f $PATH_REM/*" # clear the working directory from any previous data
printf "Working directory had been created / cleared\n"
done
TFIN=$(date +%s.%N) # time tracking
DIFF=$(echo "$TFIN - $TSTART" | bc)
printf "Time spent on distributor initialization: %.0f\n" $DIFF
printf "Done checking connectivity\n"