How can I examine that a remote computer system is on-line for ssh/ manuscript accessibility?

I'm creating a manuscript that will certainly backup information from my laptop computer to an Ubuntu web server. To do so, I'm seeking a (bachelor's degree) sh command to examine if the web server is readily available prior to beginning the backup. something like ping on port 22 that returns a boolean.

Just how can I do this?

0
2019-05-18 22:18:59
Source Share
Answers: 3

Use netcat:

nc -z localhost 22

From the manpage

 -z      Specifies that nc should just scan for listening daemons,
         without sending any data to them.
0
2019-05-21 08:55:37
Source

Like this:

nc -z hostname 22 > /dev/null
echo $?

If it is 0 after that it is readily available. If it is 1 after that it is not.

0
2019-05-21 08:52:50
Source

What concerning

MACHINE=192.168.0.8
exec 3>/dev/tcp/${MACHINE}/22
if [ $? -eq 0 ]
then
    echo "SSH up"
else
    echo "SSH down"
fi
0
2019-05-21 08:48:53
Source