0

I am creating/running a shell script from linux/Fedora server that is renaming multiple devices to default. Once it does the first device it hangs because the connection is not closing. the script is defaulting the ips and restarts the network service. How can I close the connection while that runs on the device?

Here is the script that resets them.

/bin/ssh $CHECKME -o ConnectTimeout=5 "/usr/local/bin/NameTerm.sh reset"

The CHECKME is from where I get the ips of the connected devices and runs fine. The NameTerm.sh is a shell script that sets the IP address back to 0.0.0.0 and then does a service network restart. I cannot alter the script.

  • 1
    Please post the script NameTerm.sh – Rui F Ribeiro Jan 17 '18 at 12:42
  • does NameTerm do something that breaks the SSH connection or prevents it from working? – ilkkachu Jan 17 '18 at 13:42
  • Yes, it sets the ips back to 0.0.0.0 and then does a service network restart. I cannot change the code within the shell and have to figure out how to "break" the connection once my script runs so it moves on to the next device. – Micah Jan 17 '18 at 13:46
1

If the SSH server disappears, the TCP connection is still alive from the client's point of view, and the SSH client waits it by default.

The ConnectTimeout option makes no difference, as per the name, it's used when connecting, not when the connection is already active.

Instead, you probably want to use ServerAliveInterval and ServerAliveCountMax:

ServerAliveCountMax

Sets the number of server alive messages (see below) which may be sent without ssh(1) receiving any messages back from the server. If this threshold is reached while server alive mes‐ sages are being sent, ssh will disconnect from the server, terminating the session.

ServerAliveInterval     

Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server.

This would wait for about 3x5 = 15 seconds, though ServerAliveCountMax is set to 3 by default, so you only need to set ServerAliveInterval.

ServerAliveCountMax 3
ServerAliveInterval 5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.