title: expect script to ssh returns invalid command name
body: <p>I am trying to write an expect script which would ssh into a server, send sudo su, then check the iptables status and put the output in a log file on the server. Below is the script.</p>
  
  <pre><code>1 #!/usr/bin/expect
    2 exp_internal 1
    3 log_user 0
    4 set timeout 10
    5 set password  "******"
    6 
    7 spawn /usr/bin/ssh -l subhasish *.*.*.* -p 10022
    8 
    9 expect {
   10      -re "password: " {send "$password\r"}
   11      -re "$ "  {send "sudo su\r"}
   12      -re "[sudo] password for subhasish:" {send "$password\r"}
   13      -re "# "  {send "service iptables status\r"}
   14        }
   15 set output $expect_out(buffer)
   16 send "exit\r"
   17 puts "$output\r\n" &gt;&gt; output.log
  </code></pre>
  
  <p>But while run in debug mode, I am getting error like this;</p>
  
  <pre><code>expect -d testcase
  expect version 5.44.1.15
  argv[0] = expect  argv[1] = -d  argv[2] = testcase  
  set argc 0
  set argv0 "testcase"
  set argv ""
  executing commands from command file testcase
  parent: waiting for sync byte
  parent: telling child to go ahead
  parent: now unsynchronized from child
  spawn: returns {24105}
  invalid command name "sudo"
      while executing
  "sudo"
      invoked from within
  "expect {
       -re "password: " {send "$password\r"}
       -re "$ "  {send "sudo su\r"}
       -re "[sudo] password for subhasish:" {send "$password\r"}
   ..."
      (file "testcase" line 9)
  </code></pre>
  
  <p>Not sure where I am going wrong. It says invalid command name "sudo", I guess this is because expect doesn;t understand these command. How to go around it. Please help. Thanks.</p>