-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
util.sh
61 lines (52 loc) · 947 Bytes
/
util.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
ssh_eval(){
hr; echo -e "[EXEC] $1\n"
ssh "$SSH_USER@$ADDR" $1
echo
}
ssh_push(){
echo "[info] copy $PWD/$1 to $2$1 on remote filesystem"
if [[ -d $1 ]]; then
scp -r "$1" "$SSH_USER@$ADDR:$2"
else
scp "$1" "$SSH_USER@$ADDR:$2"
fi
echo
}
task(){
read -p "$1? [y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
source $2
fi
echo
}
hr(){
printf '\e[90m%*s\n\n\e[0m' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
}
healthcheck(){
# echo "testing via ping..."
# ping -q -c3 "$ADDR" > /dev/null
#
# if [ $? -ne 0 ]
# then
# echo "ping failed at: $ADDR"
# exit 1
# fi
echo "testing ssh access..."
ssh -q "$SSH_USER@$ADDR" "exit"
if [ $? -ne 0 ]
then
echo "ssh failed for user $SSH_USER at: $ADDR"
if [ $? -eq 255 ]
then
ssh "$SSH_USER@$ADDR" "exit"
fi
exit 1
fi
echo "[info] found host at: $ADDR"
echo
hr
ssh_eval "system resource print"
hr
}