-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh_connectivity_check.sh
More file actions
39 lines (31 loc) · 888 Bytes
/
Copy pathssh_connectivity_check.sh
File metadata and controls
39 lines (31 loc) · 888 Bytes
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
#!/usr/bin/env bash
<<"COMMENT"
This script will check ssh connectivity
source: https://medium.com/@linuxadminhacks/check-ssh-connectivity-to-a-remote-server-9eda58a612ad
COMMENT
# prompt for user input
read -p "Enter remote user: " USER;
read -p "Enter remote server: " SERVER;
read -p "Enter remote timeout in seconds: " TIMEOUT;
# check that variables are not empty
if [[ -z $USER ]] || [[ -z $SERVER ]]
then
# display message
echo "Please provide both the remote user and server.";
# error exit
exit 1;
fi
# if timeout variable is empty set to 5 seconds
if [[ -z $TIMEOUT ]]
then
TIMEOUT=5;
fi
# command to test ssh connection
ssh -q -o ConnectTimeout=${TIMEOUT} ${USER}@${SERVER} exit 2>/dev/null;
# if command was successful
if [[ $? == 0 ]]
then
echo "SSH connection $USER@$SERVER was successful.";
else
echo "SSH connection failed";
fi