Hi there
Well, it's my first time on this board, so short to myself:
I'm matibaski, working as a webdeveloper and also as a system administrator on ubuntu server machines.
The problem:
I created a small apache-hostingscript by myself and it works fine.
But after some addings and new features, the script grew really fast and big, so I decided to export some config definitions into an external file and include it into the main script.
main script file: hosting.sh
external script file: vars.sh
In my vars.sh file I pasted just the apacheconfig's, wich I'm going to use in the hosting.sh.
vars.sh:
apacheconfig="<VirtualHost *:80>\n
\tServerName "$domain"\n
\tServerAlias www."$domain"\n
\tServerAdmin webmaster@"$domain"\n
\tDocumentRoot /var/www/"$domain"/htdocs\n
\n
\t<Directory /var/www/"$domain"/htdocs>\n
\t\t Options Includes FollowSymLinks MultiViews\n
\t\t AllowOverride All\n
\t\t Order allow,deny\n
\t\t allow from all\n
\t</Directory>\n
\n
\t# CGI BIN location\n
\tScriptAlias /cgi-bin/ /var/www/"$domain"/cgi-bin/\n
\t<Directory \"/var/www/"$domain"/cgi-bin\">\n
\t\t AllowOverride None\n
\t\t Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch\n
\t\t Order allow,deny\n
\t\t Allow from all\n
\t</Directory>\n
\n
\t# Log Settings\n
\tErrorLog /var/www/"$domain"/logs/error.log\n
\tLogLevel warn\n
\tCustomLog /var/www/"$domain"/logs/access.log combined\n
</VirtualHost>\n
\n"
As you can see, I put the whole apacheconfigfile into a variable.
And now i will use it in my script, hosting.sh:
# configs
cPath=/usr/bin/hostingscript
cVars=vars.sh
source "$cPath/$cVars"
domain=$1
...
configfile="/etc/apache2/sites-available/"$domain
config="${apacheconfig}"
touch $configfile
if test -f $configfile ; then
echo -e $config>$configfile
ln -s /etc/apache2/sites-available/$domain /etc/apache2/sites-enabled/$domain
echo ""
echo "I am about to reload apache:"
sh /etc/init.d/apache2 reload
else
echo "ERROR"
exit
fi
...
Should work fine, aight?
Now the gag is, when he's up to create the apache-configfile, he does it very well.
But the content of the file looks like this:
<VirtualHost *:80>
ServerName
ServerAlias www.
ServerAdmin webmaster@
DocumentRoot /var/www//htdocs
...
It seems that hosting.sh loads the vars.sh correctly, but not replacing the $domain var.
How can I fix this?
Never seen this before.
To be honest, I'm more a PHP/JS programmer than a shell/bash scripter.
Kind regards
matibaski