Create vhost-file from mysql via shell script

158 views Asked by At

I would like to create a configuration with a script from a database. The configuration is stored as:

<VirtualHost *:80>
  ServerName example.com
  ProxyRequests Off
  ProxyPreserveHost On
  <Proxy *>
    Require all granted
  </Proxy>
  ProxyPass / http://10.20.30.50:81/ retry=1 timeout=30
  ProxyPassReverse / http://10.20.30.50:81/
  <Location />
    Require all granted
  </Location>
</VirtualHost>

Apache gives me the following error message:

apache2: Syntax error on line 219 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/sites-enabled/example.com.conf: /etc/apache2/sites-enabled/example.com.conf:1: was not closed.

My script look likes:

sql="SELECT domain, vhost from v_create_proxy_vhost where domain = 'example.com'"

while read vhost
do
        echo "${vhost}"
        printf "${vhost}" > "$vhostconfavailable/$domain.conf"

done < <(echo "$sql" |mysql -h $dbHost -u $dbUser -p$dbPassword --skip-column-names -s)

How can I read this and save it as a configuration file? Apache I've been using Ubuntu 04.14, MySQL and Apache2.

1

There are 1 answers

0
Jigar Vyas On
  • the line number (219) on the error suggests how you are trying to append an existing apache conf file, in which case I might be able to better serve by getting a look at the entire conf file - which is likely to point an unclosed directive tag somewhere

    OR

  • instead of appending an existing conf file to set up vhosts, how about setting up individual conf files for each vhost, thus reducing any risk of modifying any existing vhost directives ?