0

I try building an Bash Script to auto generate Apache VHosts, secure them and enable them. So far so good, the problem is that the script does not execute the full correct line.

This is the line in the Script a2ensite /etc/apache2/sites-available/$Domain.conf

But it only executes a2ensite /etc/apache2/sites-available/$Domain

This ends up that apache does not find the config file

The $Domain does get set like this Domain=$VAR_C and does work at other commands like I want it to.

Thanks for your help

lucaslugao
  • 173
  • 6
  • Use `set -x` to see what you're actually running (see [how to debug a bash script](https://stackoverflow.com/questions/951336/how-to-debug-a-bash-script)). Maybe there's a trailing space or carriage return. Always quote variable expansions. – that other guy Jun 22 '18 at 23:29
  • 1
    In addition to using `set -x` to see what's going on, I'd recommend running your script through [shellcheck.net](https://www.shellcheck.net) and fixing the problems it points out. If you can't solve it based on either of those, edit your question to include enough information that someone else can reproduce the problem (i.e. a [mcve]). – Gordon Davisson Jun 23 '18 at 00:11
  • Besides the `set -x`, you might try quoting the path: `a2ensite "/etc/apache2/sites-available/$Domain.conf"`. Check that `$Domain` does not have any special characters on the end of it, like a newline or carriage-return. Also try `Domain="$VAR_C"` – cdarke Jun 23 '18 at 06:52
  • `+ a2ensite /etc/apache2/sites-available/test.conf ERROR: Site /etc/apache2/sites-available/test does not exist`' That is what I found while debugging, but the file exists – Jan Daltrop Jun 24 '18 at 19:25

0 Answers0