title: multiple ssh to cisco routers using expect script
body: <p>I am not a hardcore script guy,but trying to learn.I just started with expect scripts to automate tasks on cisco router.Please be gentle and nudge me in the right direction.I will do research accordingly thereafter.</p>
  
  <p>Requirement: to spawn 2 ssh sessions to 2 different cisco routers and run unique commands on each of them in a single expect script.</p>
  
  <p>Current Method : I call this expect script using a regular bash script.I can achieve the requirement using two expect scripts,But I want to do this using one expect script.</p>
  
  <p>Example: 
      # Set variables
      set router1 [lindex $argv 0]
      set router2 [lindex $argv 1]
      set username [lindex $argv 2]
      set password [lindex $argv 3]</p>
  
  <pre><code>spawn ssh -o StrictHostKeyChecking=no $username\@$router1
  
  expect "*assword"
  send "$enablepassword\n"
  expect "#"
  send "command on router1"
  expect "#"
  
  close
  
  #i want to close this ssh session and spawn ssh process to router2
  
  
  spawn ssh -o StrictHostKeyChecking=no $username\@$router2 
  #i tried this     simply in the same script and it doesn't work,mostly      because #it is not correct 
  
  expect "*assword"
  send "$enablepassword\n"
  expect "#"
  send "command on router2"
  expect "#"
  </code></pre>