title: Run cat on remote computer and send output a variable using expect
body: <p>I have a bash+expect script which has to connect via ssh to the remote comp (and i can't use ssh keys, need password identification in here), read the file there, find specific line with the "hostname" (like "hostname aaaa1111") and store this hostname into the variable to be used after while. How can i get the value of the "hostname" parameter? I thought that line content will be in $expect_out(buffer) variable (so i can scan it and analyze), but it's not. My script is:</p>
  
  <pre><code>    #!/bin/bash        
      ----bash part----
      /usr/bin/expect &lt;&lt; ENDOFEXPECT
      spawn bash -c "ssh root@$IP"  
      expect "password:"
      send "xxxx\r"
      expect ":~#"
      send "cat /etc/rc.d/rc.local |grep hostname \r"
      expect ":~#"
      set line $expect_out(buffer)
      puts "line = $line, expect_out(buffer) = $expect_out(buffer)"
      ...more script...
      ENDOFEXPECT
  </code></pre>
  
  <p>When i try to see line variable, i see only this: <code>line = , expect_out(buffer) = (buffer)</code> What is the right way to get the line from the file into the variable? 
  Or is it possible to open the file <em>on the remote computer</em> with expect, scan the file and get what i need to the variable?
  Here <a href="http://en.wikipedia.org/wiki/Expect" rel="nofollow">http://en.wikipedia.org/wiki/Expect</a> there is an example:</p>
  
  <pre><code>    # Send the prebuilt command, and then wait for another shell prompt.
      send "$my_command\r"
      expect "%"
      # Capture the results of the command into a variable. This can be displayed, 
      set results $expect_out(buffer)
  </code></pre>
  
  <p>seems that it doesn't work in this case?</p>