I am attempting to create a simple script which will generate files in /etc/apache2/sites-available
directory using a for loop, and get it to do this using a template within my script. This is what the snippet of my script looks like:
cat <<EOF > /etc/apache2/sites-available/${VHOST}.com.conf
<VirtualHost *:80>
ServerName ${VHOST}.com
ServerAlias www.${VHOST}.com
ServerAdmin [email protected]
DocumentRoot /var/www/${VHOST}.com
ErrorLog ${APACHE_LOG_DIR}/${VHOST}_error.log
CustomLog ${APACHE_LOG_DIR}/${VHOST}_access.log combined
Options -Indexes
</VirtualHost>
EOF
NOTE: ${VHOST} is simply a value specified within my for loop.
The result which I am trying to achieve is that the template output will be sent to a file ${VHOST}.com.conf
within the sites-available directory.
My above snippet does not work and I receive the following errors:
./vhost.sh: line 21: warning: here-document at line 6 delimited by end-of-file (wanted `EOF')
./vhost.sh: line 21: syntax error near unexpected token `newline'
./vhost.sh: line 21: `<<-EOF <VirtualHost *:80>'
UPDATE:
I followed @PerlDuck's suggestion by updating the file as follows
cat > /etc/apache2/sites-available/${VHOST}.com.conf <<-EOF
<VirtualHost *:80>
ServerName ${VHOST}.com
ServerAlias www.${VHOST}.com
ServerAdmin [email protected]
DocumentRoot /var/www/${VHOST}.com
ErrorLog ${APACHE_LOG_DIR}/${VHOST}_error.log
CustomLog ${APACHE_LOG_DIR}/${VHOST}_access.log combined
Options -Indexes
</VirtualHost>
Attempting cat > /etc/apache2/sites-available/${VHOST}.com.conf <<- "EOF"
also did not work. Both produce the same error.
./vhost.sh: line 22: warning: here-document at line 6 delimited by end-of-file (wanted `EOF')
./vhost.sh: line 23: syntax error: unexpected end of file
@PerlDuck resolved my issue for me. This is simply a case of unwanted blank space. This extra whitespace after the final EOF prevents the heredoc from terminating. Thus producing the error
Remember kids! Blankspace, blankspace, blankspace !