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
bash: command substitution: line 1: syntax error near unexpected token newline'
bash: command substitution: line 1:
echo '
Could anyone tell what is exact way to append simple text file by echo a variable having multiple lines.
My expect script is as follows:
#!/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 >> /etc/httpd/conf/httpd.conf`
expect "*assword: "
send "redhat\r"
interact
and the variable "remote_command" contains a pattern of virtual host entries. used printf but still same problem exists. –
my remote_command contains following values
<VirtualHost>
DirectoryIndex index.php
</VirtualHost>
it still giving same error.I used "" quotes but it worked for a single line , and not for multiple lines.
My main script script.sh contains lines
#!/bin/bash
some code .....
some code......
some code ......
echo "<VirtualHost $D_IPADDRESS>" > /opt/remotehttpd_conf
awk "p && /\/VirtualHost/{exit} /$SITENAME/{p=1}p" /opt/httpd.conf >> /opt/remotehttpd_conf
echo "</VirtualHost>" >> /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 .....
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
my expect_remote_command_httpd.exp contains
#!/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 >> /etc/httpd/conf/httpd.conf`
expect "*assword: "
send "redhat\r"
interact
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.