I have a httpd.conf file for a shared hosting server, and I have the task of moving each virtual host to vps. using awk, I retrieve the virtual host write block for a specific site. and save this entry in a variable. but when I return out to add httpd.conf for the vps server it gives an error like
bash: command substitution: line 1: syntax error near unexpected token newline' bash: command substitution: line 1: echo'
Can anyone say what is the exact way to add a simple text file by echoing a variable with multiple lines.
My expectation script looks like this:
#!/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 the host virtual entry template. used printf, but still the same problem exists. -
my remote_command contains the following values
<VirtualHost> DirectoryIndex index.php </VirtualHost>
he still gives the same error. I used quotation marks, but it worked for a single line, not 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 gives me output, so I use the expect_remote_command_httpd.exp function to send the output to the 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 does not work. Maybe what approach I use is completely wrong. My main task is to extract all the lines of the virtual host block associated with these sites on the shared httpd server and pass them to the remote vps httpd conf file.i, if you suggest any other way.