Strange terminal behaviour after killing ssh

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Strange terminal behaviour after killing ssh
# 1  
Old 08-08-2011
Strange terminal behaviour after killing ssh


We have a problem where occasionally an ssh will hang for no apparent reason preventing the rest of the script continuing. To deal with this I am trying to write a wrapper script to kill a hung ssh command after a specified period.

The scripts use a sleep command running in the background to determine the timeout period. However after I kill the ssh command the terminal goes (for want of a better word) weird. The sysmptoms are:
Unable to type anything
Pressing enter brings up a new line prompt but on the same line as the previous one (sorry I'm not sure on the real terminology - the text at the start showing the current directory)
Ctrl C works the way I would expect enter to work.

I have two versions of the script, one of which always tries to kill the ssh command when the sleep command exits and the other of which only tries to do it, if it has not already died. Both exhibit the same syptoms following the ssh kill so I have currently only posted one here.


# Set up a sleep thread that will run in the background and simply sleep for the requisite number of seconds.
sleep $1 &
echo $sleep_pid
# Set up the SSH thread to run the command. Also runs in the background
ssh -t -t $2 $3 $4 $5 $6 $7 $8 $9 &
while :
  ssh_cnt=$(ps -eaf | grep $ssh_pid | wc -l)
  sleep_cnt=$(ps -eaf | grep $sleep_pid | wc -l)
  if [ 1 -eq $ssh_cnt ]
    if [ 1 -lt $sleep_cnt ]
      kill -11 $sleep_pid
    if [ 1 -eq $sleep_cnt ]
      kill -11 $ssh_pid

To me it seems like the kill command hasn't killed everything that it needs to, but I really have no idea and wondered if you could help. I am testing this performing an ssh that requires a password so that it hangs.
# 2  
Old 08-08-2011
Apparently it doesn't clean up after itself when killed in that fashion. If you killed it with a less severe signal than SEGV it might. Give it TERM, then QUIT, then KILL if those don't work.

You can reset the terminal characteristics back to normal with reset.
# 3  
Old 08-10-2011
ooh, you are wonderful. I changed it to kill -15 $ssh_pid and it seems to all be working fine. Thank-you so much.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Strange behaviour when output to terminal vs file (awk)

Hi all ! I noticed something very weird. I have a large pipe delimited file (20 fields/3,000 records) that looks like that: AAA|BBB|11111|22222|...|($NF of record 1) CCC|DDD|33333|44444|...|($NF of record 2) CCC|DDD|55555|66666|...|($NF of record 3) For the lines with same 1st and 2nd... (3 Replies)
Discussion started by: beca123456
3 Replies

2. Red Hat

Crontab strange behaviour

Hi all, I'm having this scenario which for the moment I cannot resolve. :( I wrote a script to make a dump/export of the oracle database. and then put this entry on crontab to be executed daily for example. The script is like below: cat /home/oracle/scripts/ #!/bin/ksh ... (3 Replies)
Discussion started by: enux
3 Replies

3. Shell Programming and Scripting

Strange RegExp Behaviour

Hello, I was trying to identify lines who has a word of the following pattern "xyyx" (where x, and ys are different characters). I was trying the following grep - egrep '(\S)()\2\1' This pattern do catches the wanted pattern, but it also catches "GGGG" or "CCCC" patterns. I was trying to... (5 Replies)
Discussion started by: itskov
5 Replies

4. HP-UX

Strange login behaviour

Hi all, I am using HP-UX and I have just noticed that when I log into the network it seems to save the previous windows that were subsequently closed on previous occasions. Does anyone know when I log in, it seems to display these previous windows, e.g. nedit windows open again? Does... (1 Reply)
Discussion started by: cyberfrog
1 Replies

5. Shell Programming and Scripting

strange behaviour from sed???

Hi all, I want to do a very simple thing with sed. I want to print out the line number of a disk I have defined in /etc/exports, so I do: It's all good, but here's the problem. When I define md0 in a variable, I get nothing from sed: Why is that? can anybody please help? Thanks (2 Replies)
Discussion started by: alirezan
2 Replies

6. UNIX for Dummies Questions & Answers

Strange Program behaviour

Had a strange thing going on with my code. It's ok I figured it out for myself.... (2 Replies)
Discussion started by: mrpugster
2 Replies

7. UNIX for Advanced & Expert Users

Strange sed behaviour

$ echo a.bc | sed -e "s/\|/\\|/g" |a|.|b|c| $ Is the behavior of the sed statement expected ? Or is this a bug in sed ? OS details Linux 2.6.9- #1 SMP Wed May 2 14:59:56 PDT 2007 i686 i686 i386 GNU/Linux (8 Replies)
Discussion started by: vino
8 Replies

8. Shell Programming and Scripting

A Strange Behaviour!!!

Can some-one give me a view to this : I have a directory in an unix server, having permissions r-xr-xr-x .This directory is basically a source directory. Now there is another directory basically the destination directory which has all the permissions. Note:I log in as not the owner,but user... (5 Replies)
Discussion started by: navojit dutta
5 Replies

9. Linux

/etc/passwd strange behaviour!

Hi there, first of all, here is my conf of a uname -a Linux SAMBA 2.4.18-4GB #1 Wed Mar 27 13:57:05 UTC 2002 i686 unknown on a fedora machine. Here is my problem: every once in a while, the line containing root disappears in the /etc/passwd, disabling all logging on my server. Any one have... (0 Replies)
Discussion started by: penguin-friend
0 Replies
Login or Register to Ask a Question