title: echo multiple lines into a file
body: <p>I have a httpd.conf file of  shared hosting server and I have a task to migrate every virtual host to a vps. using awk I extract a block of virtual host entry for a particular site. and store that entry in a variable. but when i echo the out put  of the variable to append httpd.conf of vps server it gives a error like </p>
  
  <p>bash: command substitution: line 1: syntax error near unexpected token <code>newline'
  bash: command substitution: line 1:</code>echo '</p>
  
  <p>Could anyone tell what is exact way to append simple text file by echo a variable having multiple lines.</p>
  
  <p>My expect script is as follows: </p>
  
  <pre><code>#!/usr/bin/expect 
  set remote_ip [lindex $argv 0] 
  set username [lindex $argv 1] 
  set remote_command [lindex $argv 2] 
  foreach {remote_ip username remote_command} $argv {break} 
  spawn ssh -o "StrictHostKeyChecking no" root@$remote_ip `echo $remote_command &gt;&gt; /etc/httpd/conf/httpd.conf`
  expect "*assword: " 
  send "redhat\r" 
  interact 
  </code></pre>
  
  <p>and the variable "remote_command" contains a pattern of virtual host entries. used printf but still same problem exists. –</p>
  
  <hr>
  
  <p>my remote_command contains following values </p>
  
  <pre><code>&lt;VirtualHost&gt;
  DirectoryIndex index.php
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>it still giving same error.I used "" quotes but it worked  for a single line , and not for multiple lines. </p>
  
  <p>My main script script.sh contains lines </p>
  
  <pre><code>#!/bin/bash
  some code .....
  some code......
  some code ......
  echo "&lt;VirtualHost $D_IPADDRESS&gt;" &gt; /opt/remotehttpd_conf
  awk "p &amp;&amp; /\/VirtualHost/{exit} /$SITENAME/{p=1}p" /opt/httpd.conf &gt;&gt; /opt/remotehttpd_conf
  echo "&lt;/VirtualHost&gt;" &gt;&gt; /opt/remotehttpd_conf
  REMOTE_COMMANDS4=`cat /opt/remotehttpd_conf`
  echo $REMOTE_COMMANDS4
  ./expect_remote_command_httpd.exp  "$D_IPADDRESS" "$USERNAME" "$REMOTE_COMMANDS4"
  some code .....
  some code .....
  </code></pre>
  
  <p>when I echo REMOTE_COMMANDS4 it works fine and give me output so i use expect_remote_command_httpd.exp to transfer the output to remote machine</p>
  
  <p>my expect_remote_command_httpd.exp contains </p>
  
  <pre><code>#!/usr/bin/expect 
  set remote_ip [lindex $argv 0] 
  set username [lindex $argv 1] 
  set remote_command [lindex $argv 2] 
  foreach {remote_ip username remote_command} $argv {break} 
  spawn ssh -o "StrictHostKeyChecking no" root@$remote_ip `echo $remote_command &gt;&gt;   /etc/httpd/conf/httpd.conf`
  expect "*assword: " 
  send "redhat\r" 
  interact 
  </code></pre>
  
  <p>but its not working. May be what approach i am using is totally wrong.  My main concern is to extract all lines of virtual host block related to given sites in shared httpd server and trnsfer it to remote vps's httpd conf file.i will appreciate if you will suggest any other way.  </p>