P
P
Printip2017-01-23 11:42:10
linux
Printip, 2017-01-23 11:42:10

How to make an infinite ssh connection check loop?

There is a task to constantly check (in an infinite loop) the presence of an ssh connection to the server.
The algorithm of the script is approximately the following:
1. Server A connects via ssh to server B
2. Server A checks if there is an ssh connection to server B
A. If there is a connection, does nothing
B. If there is no connection, server A reconnects via ssh to to server B
3. Pause of 10 seconds
4. Server A checks if there is a connection via ssh to server B
A. If there is a connection - does nothing
B. If there is no connection - server A reconnects via ssh to server B
3. Pause of 10 seconds
And then in the same vein.
Please tell me how to implement?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Shelemetiev, 2017-01-23
@zoroda

It looks like HERE your problem is described and a solution is given

A
Azazel PW, 2017-01-23
@azazelpw

Yes, you, my friend, are a fan of complicating tasks :))))
1. You need to make ssh authorization by key
2. crontab runs every 10 seconds, I would give 30
3. Script that checks for a connection
#!/bin/bash
netstat -a |grep 94 -180 |grep ESTABLISHED
if [$? -ne0]; then
echo "FAILED"
else
echo "CONNECTED"
fi
I hope it will be clear further where to enter what

J
jcmvbkbc, 2017-01-23
@jcmvbkbc

how to implement

take autossh

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question