title: Expect script procedure seems to be quitting and the rest of the script is not quite following execution
body: <p>So I used to have a script that would log into a switch and interact, or run a bunch of commands and quit. 
  Well, i tried to make it more secure by incorporating a function from another file, and now things are just not working.
  It seems that when the function is done, the ssh session quits, interact in function or outside is not working, and certainly following up with more commands is not going well....</p>
  
  <p>I would appreciate some ideas on what is wrong:</p>
  
  <p>1st script containing the function [ ssssh2 ]:</p>
  
  <pre><code>#!/usr/bin/expect   
  
  proc log-in { host } {
   set timeout 20
   set passfile [open "~/bin/.l" r]
   gets $passfile pass
   gets $passfile enab
   gets $passfile user
   close $passfile
  
   spawn ssh $user@$host
  
   expect -timeout 5 {
    "yes/no" { send "yes\r" }
    "#" {}
    }
   expect "word"
   send "$pass\r" 
   expect { 
    "#" {}
    "&gt;" {
    send "en\r"
    expect "word"
    send "$enab\r" 
    }
   }
   send "\r"
   expect "#"
   send "terminal length 0\r"
   expect "#"
  }
  </code></pre>
  
  <p>Here's the script that calls it - at this point i want interact at the end, in other variations it might be an ongoing string of switch commands ending with logout. This script runs with -d for debug [sssh2 ]</p>
  
  <pre><code>#!/usr/bin/expect  -d 
  source ~/bin/ssssh2
  
  log-in $argv 
  
  send "\r"
  expect "#"
  send "terminal length 50\r"
  expect "#"
  
  interact
  </code></pre>
  
  <p>And here's the output in debug mode:</p>
  
  <pre><code># sssh2 host***
  expect version 5.45
  argv[0] = /usr/bin/expect  argv[1] = -d  argv[2] = /root/bin/sssh2  argv[3] = host***  
  set argc 1
  set argv0 "/root/bin/sssh2"
  set argv "host***"
  executing commands from command file /root/bin/sssh2
  spawn ssh user***@host***
  parent: waiting for sync byte
  parent: telling child to go ahead
  parent: now unsynchronized from child
  spawn: returns {3729}
  
  expect: does "" (spawn_id exp7) match glob pattern "\n  "yes/no" { send "yes\r" }\n  "#" {}\n  "? no
  host*** Radius Enabled
  
  expect: does "host*** Radius Enabled\r\r\n" (spawn_id exp7) match glob pattern "\n  "yes/no" { send "yes\r" }\n  "#" {}\n  "? no
  user***@host***'s password: 
  expect: does "host*** Radius Enabled\r\r\nuser***@host***'s password: " (spawn_id exp7) match glob pattern "\n  "yes/no" { send "yes\r" }\n  "#" {}\n  "? no
  expect: timed out
  
  expect: does "host*** Radius Enabled\r\r\nuser***@host***'s password: " (spawn_id exp7) match glob pattern "word"? yes
  expect: set expect_out(0,string) "word"
  expect: set expect_out(spawn_id) "exp7"
  expect: set expect_out(buffer) "host*** Radius Enabled\r\r\nuser***@host***'s password"
  send: sending "mypass***\r" to { exp7 }
  
  expect: does ": " (spawn_id exp7) match glob pattern "#"? no
  "&gt;"? no
  
  
  expect: does ": \r\n" (spawn_id exp7) match glob pattern "#"? no
  "&gt;"? no
  
  host***&gt;
  expect: does ": \r\n\r\nhost***&gt;" (spawn_id exp7) match glob pattern "#"? no
  "&gt;"? yes
  expect: set expect_out(0,string) "&gt;"
  expect: set expect_out(spawn_id) "exp7"
  expect: set expect_out(buffer) ": \r\n\r\nhost***&gt;"
  send: sending "en\r" to { exp7 }
  
  expect: does "" (spawn_id exp7) match glob pattern "word"? no
  e
  expect: does "e" (spawn_id exp7) match glob pattern "word"? no
  n
  Password:
  expect: does "en\r\nPassword:" (spawn_id exp7) match glob pattern "word"? yes
  expect: set expect_out(0,string) "word"
  expect: set expect_out(spawn_id) "exp7"
  expect: set expect_out(buffer) "en\r\nPassword"
  send: sending "mypass2***\r" to { exp7 }
  send: sending "\r" to { exp7 }
  
  expect: does ":" (spawn_id exp7) match glob pattern "#"? no
  *
  expect: does ":*" (spawn_id exp7) match glob pattern "#"? no
  *****************
  
  host***#
  host***#
  expect: does ":******************\r\n\r\nhost***#\r\nhost***#" (spawn_id exp7) match glob pattern "#"? yes
  expect: set expect_out(0,string) "#"
  expect: set expect_out(spawn_id) "exp7"
  expect: set expect_out(buffer) ":******************\r\n\r\nhost***#"
  send: sending "terminal length 0\r" to { exp7 }
  
  expect: does "\r\nhost***#" (spawn_id exp7) match glob pattern "#"? yes
  expect: set expect_out(0,string) "#"
  expect: set expect_out(spawn_id) "exp7"
  expect: set expect_out(buffer) "\r\nhost***#"
  }end: sending "\r" to { exp0 
  
  expect: does "" (spawn_id exp0) match glob pattern "#"? no
  expect: timed out
  }end: sending "terminal length 50\r" to { exp0 terminal length 50
  
  expect: does "" (spawn_id exp0) match glob pattern "#"? no
  expect: timed out
  cannot interact with self - set spawn_id to a spawned process
      while executing
  "interact"
      (file "/root/bin/sssh2" line 11)
  </code></pre>
  
  <p>I am at a loss here..... Thx for any help!</p>
  
  <p>GT</p>