3

I keep getting this error, do you guys know what is wrong?

rapache is an alias for restart apache

mugbear:/usr/bin# cat /usr/bin/mkdomain                                         
if [ -d "/srv/www/$1" ]; then
        echo "Domain $1 already exists!"
else
        mkdir -p /srv/www/$1/public_html
        mkdir -p /srv/www/$1/logs
        cat >> /etc/apache2/sites-available/"$1" << EOF
        <VirtualHost removed:80>
                ServerAdmin support@$1
                ServerName $1
                ServerAlias www.$1
                        DocumentRoot /srv/www/$1/public_html/
                ErrorLog /srv/www/$1/logs/error.log
                CustomLog /srv/www/$1/logs/access.log combined
        </VirtualHost>
        EOF
        a2ensite $1
    rapache
fi
mugbear:/usr/bin# mkdomain test.com                                        
/usr/bin/mkdomain: line 19: syntax error: unexpected end of file
Strawberry
  • 1,132
  • 4
  • 15
  • 27

2 Answers2

3

Your heredoc never ends since the terminator is not at the beginning of the line.

Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
3
someFile <<EOF
...
EOF

works


    someFile <<EOF
    ...
    EOF

will not work


    someFile <<-EOF
    ...
    EOF

works


See 'man bash' and the Bash Reference Manual, section "3.6.6 Here Documents" for details on <<-EOF. Note that the indentation of the heredoc terminator must be done using tabs, not spaces.

Stefan Lasiewski
  • 23,667
  • 41
  • 132
  • 186
Arno Nym
  • 31
  • 1
  • Good point re: `<<-EOF`. I fixed your formatting and added the detail about tabs for you. – MikeyB Mar 24 '11 at 16:43
  • +1 for mentioning `<<-EOF`. Also see [Bash Reference Manual, section "3.6.6 Here Documents"](http://www.gnu.org/software/bash/manual/bashref.html#Redirections) for an explanation. I added some links to your answer. – Stefan Lasiewski Mar 24 '11 at 16:58