I am working on creating a simple script to make it easy to set up a virtual host on Apache server. Currently I don't seem to be able to write the config file because it's in a variable. How do I get around it. Here is my code that does not work.
siteConf="/etc/apache2/sites-available/$domain.conf"
echo "creating conf file"
echo "<VirtualHost *:80>" >> $siteConf
echo "ServerName *.$domain" >> $siteConf
echo "DocumentRoot $publicHtmlLoc" >> $siteConf
echo "DirectoryIndex index.php" >> $siteConf
echo "ServerAlias $database.newphp.junglecoders.dk" >> $siteConf
echo "</VirtualHost>" >> $siteConf
I am running the script with the bash command.
Edit: The Error i get is this
$siteConf: ambiguous redirect
Domain comes from here:
echo "Write websiter url example.com, no sub dir allowed"
read -p "Name: " domain
As suggested in comments its the path that is wrong, i tried to echo out the variable and i can see it has removed the '.' chars from some reason and left a space instead, why would the script do that ?
Edit2: Was using IFS earlier in the script, to split the the domain name
echo "..." >> $varnameshould work. Typicall you wan the firstecho .. > $fileto be just the single>redirection, so it deletes anything that was in the file previously. Unless you have a good reason to keep your domain.conf file, best to delete this and then try running your code again. It may be working already (if you're only looking at the :"top" of you file, it may be filled with blank lines (how do I know that ? doah!) ;-) ) . Good luck.{ echo "<VirtualHost …>"; …; echo "</VirtualHost>"; } > $siteConf(or>> $siteConf). What do you get frombash -x your-script.sh? Isdomainset in the environment? If not, you're editing the file/etc/apache2/sites-available/.conf.IFS, then its current value is probably altering how the names are being interpreted. Reinstate it to its default value (blank, tab, newline):IFS=$' \t\n'.