Remotely close & rerun SSH connection


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remotely close & rerun SSH connection
# 1  
Old 08-12-2013
Remotely close & rerun SSH connection

I'm trying to remotely run an upgrade script (via SSH) that update the SSH script on several hosts, just need to add several flags for the ssh command to look like this:

Code:
ssh -Nf -i id_logs -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -o ServerAliveCountMax=5 -R <port>:127.0.0.1:22 <user>@<host>

after successfully update the SSH script located on the remote hosts I want to restart the SSH process, then reconnect again to check the new connection has established successfully - my problem is that after I kill the SSH process I get kicked out of the host, and obviously can't rerun the SSH tunnel,

I was thinking of running another local script with sleep of 10seconds before killing the SSH process that will recover the SSH..but that doesn't work.
Does anyone has a good solution ? I think my idea is a bit primitive..there must be a better way to do it.

thanks !

Last edited by OdedOvdat; 08-12-2013 at 04:26 PM..
# 2  
Old 08-12-2013
Why are you killing the sshd? Why not restart it using service or init.d?
Yes, you will be kicked off, but you can connect back again after, say 10 sec, and verify the connection.

--ahamed

Last edited by ahamed101; 08-12-2013 at 04:30 PM..
# 3  
Old 08-12-2013
Either use a different protocol or wait longer. It sounds like you're not waiting long enough for the start. You could also add logic in the script that restarts the sshd daemon send mail to you. If you wanted to automate that you could send an email to a user account that had a .forward file or an alias pointing a script that could ssh back.
# 4  
Old 08-12-2013
I don't need to restart the SSH service
I just need to restart the SSH process so it will run with the latest configuration

the old SSH script looks like this:
Code:
ssh -Nf -i id_logs  -R <port>:127.0.0.1:22 <user>@<host>

and after the update script it looks like this:
Code:
ssh -Nf -i id_logs -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -o ServerAliveCountMax=5 -R <port>:127.0.0.1:22 <user>@<host>

so basically I need to kill the SSH tunnel (kill <pid>)
and then run again the ssh script with the latest flags
# 5  
Old 08-13-2013
IMHO you cannot kill/restart the reverse connection without killing the whole ssh.
Do the kill from a second ssh connection!
This can already be the final ssh connection if its reverse connection port is different.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Rsh does not close connection on exit

Dear all, We have a service that we start up remotely with rsh but unfortunately, the rsh never returns to the calling server. This seems to be because the processes of the service we've just started hold the port open.RBATTE1 @ /home/RBATTE1>netstat -na|grep 49.51 tcp4 0 0 ... (1 Reply)
Discussion started by: rbatte1
1 Replies

2. Solaris

SSH Remotely

Hello. I am trying to ssh and run a script from a remote computer. These computers will be both Windows and MACs. I am using Solaris 8 and what I have tried is: using putty ssh user@ip_address (remote command) /folder/folder/filename.sh The issue here is that the user profile has not... (3 Replies)
Discussion started by: jkmtm
3 Replies

3. Solaris

Ssh to Solaris 10 server - close connection

Can ssh to server. Asks for password. Then seems to time out and close the connection. Any ideas? ---------- Post updated at 09:30 AM ---------- Previous update was at 07:51 AM ---------- Here is output from ssh -vvv -l user <IPaddress> debug3: packet_send2: adding 64 (len 59 padlen 5... (4 Replies)
Discussion started by: psychocandy
4 Replies

4. UNIX for Advanced & Expert Users

How keep running a program n an another computer via a connection ssh when the connection is closed?

Hi everybody, I am running a program on a supercomputer via my personal computer through a ssh connection. My program take more than a day to run, so when I left work with my PC I stop the connection with the supercomputer and the program stop. I am wondering if someone know how I can manage... (2 Replies)
Discussion started by: TomTomGre
2 Replies

5. AIX

close ssh users to the home directory

Hello, I must close ssh users to the home directory. It means the users musn't see anything inside their home directory. For example after login to the os and type this command "cd .." or "cd /" it musn't work. How can I implement it? (Probably chroot or rootsh but how?) (1 Reply)
Discussion started by: jeszi
1 Replies

6. Solaris

many tcp connection in close-wait

Hi, I use solaris Unix . I find there is some problem in application and it generate many "close-wait" tcp connect and stay in the server . it is generate by process id 7740 root@XX # netstat -an | grep CLOSE_WAIT | wc -l 285 root@XX # netstat -an | grep CLOSE_WAIT 10.158.35.4.34805 ... (2 Replies)
Discussion started by: abcdef
2 Replies

7. Shell Programming and Scripting

Usage of NOHUP - How to keep the child process running even if I close the Server connection

Hi. ! When I use the 'NOHUP' along with the '&', the process will be running in the background. Even when I attempt to close (Meaning 'EXIT') the session (say PUTTY in this case), it wont exit unless the process is completed. But, say when I forcefully terminate the session (SHUT DOWN the... (2 Replies)
Discussion started by: WinBarani
2 Replies

8. Shell Programming and Scripting

How to close TELNET Connection

Hi, I have logged into a system using Telnet and iam unable to close the connection to connect to the next system using arrays. Iam getting error "Connection Timed Out" Iam using net::Telnet module. Please suggest.. (1 Reply)
Discussion started by: sudhakaryadav
1 Replies

9. Programming

close existing tcp connection in C

Hello. I would like to know how to close an existing tcp socket. I have read some stuff and learned how to create a socket and then close it but have not found anything about how to close an existing tcp socket created by another application. The situation is this: I have an ODBC server running and... (6 Replies)
Discussion started by: raidzero
6 Replies

10. UNIX for Dummies Questions & Answers

ftp - Connection close

Hi Can someone help me what is the problem, when i try to login via ftp, though i entered the correct password, i got an error message Connection refused. please help. thanks (3 Replies)
Discussion started by: kaibiganmi
3 Replies
Login or Register to Ask a Question