Answer the question
In order to leave comments, you need to log in
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
It looks like HERE your problem is described and a solution is given
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question