title: How to make expect nested in the bash script properly?
body: <p>Here is the expect file which can run succesfully. </p>
  
  <pre><code>#!/usr/bin/expect  -f
  set host vps_ip
  set user test
  set loginpwd  passwd
  set adminpwd  passwd
  set timeout 300
  set prompt "#|&gt;|\\\$"    
  spawn scp  /home/wpdatabase_backup.sql   $user@$host:/tmp
  expect -nocase  "password:"
  send "$loginpwd\r"
  expect eof
  spawn  ssh  $user@$host
  expect -nocase "password:"
  send "$loginpwd\r"
  expect -re $prompt
  send "su\r"
  expect  "assword:"
  send "$adminpwd\r"
  expect -re $prompt
  send "mysql -u root -pxxxx wpdatabase &lt; /tmp/wpdatabase_backup.sql\r"
  expect eof
  </code></pre>
  
  <p>Here is the bash file:</p>
  
  <pre><code>mysqlword="xxxx"
  mysqldump -u root -p$mysqlword wpdatabase &gt; /home/wpdatabase_backup.sql
  </code></pre>
  
  <p>Now i want to make the expect file nested in the bash file because the bash file is more complicated than expect file ,most lines in the bash file were omitted.</p>
  
  <p>code:</p>
  
  <pre><code>#!/usr/bin/bash
  mysqlword="xxxx"
  mysqldump -u root -p$mysqlword wpdatabase &gt; /home/wpdatabase_backup.sql    
  /usr/bin/expect &lt;&lt;EOD
  set host vps_ip
  set user test
  set loginpwd  passwd
  set adminpwd  passwd
  set timeout 300
  set prompt "#|&gt;|\\\$"
  
  spawn scp  /home/wpdatabase_backup.sql   $user@$host:/tmp
  expect -nocase  "password:"
  send "$loginpwd\r"
  expect eof
  spawn  ssh  $user@$host
  expect -nocase "password:"
  send "$loginpwd\r"
  expect -re $prompt
  send "su\r"
  expect  "assword:"
  send "$adminpwd\r"
  expect -re $prompt
  send "mysql -u root -pxxxx wpdatabase &lt; /tmp/wpdatabase_backup.sql\r"
  expect eof
  &lt;&lt;EOD
  </code></pre>
  
  <p>An error occur :
  spawn scp /home/wpdatabase_backup.sql @:/tmp<br>
  ssh: Could not resolve hostname : Name or service not known<br>
  lost connection<br>
  send: spawn id exp6 not open<br>
      while executing<br>
  "send "\r""    </p>
  
  <p>Quote the terminator:</p>
  
  <pre><code>cat&lt;&lt;'EOD'
  set host vps_ip
  set user test
  spawn scp  /home/wpdatabase_backup.sql   $user@$host:/tmp
  EOD
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>set host vps_ip
  set user test
  spawn scp  /home/wpdatabase_backup.sql   $user@$host:/tmp
  </code></pre>
  
  <p>But how to make the output of result run in bash?</p>
  
  <pre><code>/usr/bin/expect  &lt;&lt;cat&lt;&lt;'EOD'
  set host vps_ip
  set user test
  spawn scp  /home/wpdatabase_backup.sql   $user@$host:/tmp
  EOD
  </code></pre>
  
  <p>The code can't run!</p>