title: Expect script with variable hostname
body: <p>I would like to use EXPECT script for mount volume after reboot tens of our UBUNTU servers (12.04 &amp; 14.04). </p>
  
  <p>I am not able to figure out how set hostname like variable (for example to grab record from /etc/hostname ) -> I dont wanna create one script (set specific hostname) for each server. My idea is use this script global for my environment.</p>
  
  <p>Following script works fine - but there is set fix hostname</p>
  
  <pre><code>#!/usr/bin/expect -f
  
  set timeout 90
  
  set sudo_pass "Password01
  set mount_pass "Password02"
  set hostname "test-staging"          &lt;&lt;&lt;==== here I set static hostname
  
  # turns off the output to STDOUT
  log_user 0
  
  # run mount-script
  spawn sudo mount-script
  
  # type sudo pass
  expect "password for"
  send "$sudo_pass\r"
  
  # type Pass for mount-script
  expect "Enter passphrase"
  send "$mount_pass\r"
  
  # call &amp; paste hostname
  expect "Please provide a hostname for this instance,"
  send "$hostname\r"
  
  # type letter Y - for test environment
  expect "Is this a test instance?  Enter 'Y', otherwise press enter"
  send "Y\r"
  
  interact
  </code></pre>
  
  <p>I tried to google it I found commands for hostname like</p>
  
  <pre><code>send 'lsnrctl status listener_`hostname`\r'
  </code></pre>
  
  <p>or</p>
  
  <pre><code>send "cat /etc/rc.d/rc.local |grep hostname \r\n"
  </code></pre>
  
  <p>I tried set them like SET HOSTNAME and I tried call them via command send. Unfortunately, it doesn't work, too.</p>
  
  <p>this is output</p>
  
  <pre><code>    .......    
      dbg1.7&gt;
      1: expect "Please provide a hostname for this instance
      dbg1.8&gt;
      Please provide a hostname for this instance
      1: send 'lsnrctl status listener_`hostname`\r'
  
      dbg1.9&gt;
      usage: send [args] string
          while executing
      "send 'lsnrctl status listener_`hostname`\r'"
          (file "test01-expect.sh" line 38)
      1: exit 1
  </code></pre>
  
  <p>I am open mind for different solution, too.
  thank you</p>