Apache Hosting-Shell Script - external files include


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Apache Hosting-Shell Script - external files include
# 1  
Old 10-25-2012
Apache Hosting-Shell Script - external files include

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:
Code:
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:
Code:
# 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:
Code:
<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
# 2  
Old 10-25-2012
in hosting.sh, try: move line:
Code:
domain=$1

before:
Code:
source "$cPath/$cVars"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to include menu based options in Shell script?

Hi Friends, I have a menu based tool which requires input/option to proceed further. How to make a shell script ? eg: menu looks like Get_data.sh to continue (y/n) : Here I need to key in "y" to proceed. I want to prepare a script which should consider option y. (5 Replies)
Discussion started by: suresh3566
5 Replies

2. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

3. Web Development

Include CFTOKEN and CFID in apache access_log

hi folks, how to write CFID and CFTOKEN cookie in apache logs ? can you give me a link or howtos in doing this. thanks in advance (0 Replies)
Discussion started by: linuxgeek
0 Replies

4. Shell Programming and Scripting

How to include a command in shell script?

# dbc "delete from alert;" DELETE 10 # However, the script created below generates an error that command does not exits. Can any one please exist. script.sh: #!/bin/sh dbc "delete from alert;" >>$TASKLOGFILE ./script.sh: line 38: dbc: command not found can any one please... (2 Replies)
Discussion started by: sureshcisco
2 Replies

5. Web Development

hosting service that allow me to compile and install my own apache

Is there any cheap hosting service that allow me to compile and install my own apache and php ? thanks (1 Reply)
Discussion started by: aneuryzma
1 Replies

6. Shell Programming and Scripting

querry ..including external shell script

is there any way to include one shell script into other like include in c apart from putting it in a function (3 Replies)
Discussion started by: mobydick
3 Replies

7. UNIX for Dummies Questions & Answers

Include PERL script with in the unix shell script

Hi Gurus, Is it possible to include perl script with in the unix shell script? What would be the general syntax? In the above case, is it required to write the below first two lines of codes? #!usr/bin/sh -x #!usr/bin/perl -w Thanks in advance / Mysore Ganapati. (1 Reply)
Discussion started by: ganapati
1 Replies

8. Shell Programming and Scripting

how to include spreadsheet::ParseExcel in shell script

Please tell me that how can we include Spreadsheet::ParseExcel module in shell script (1 Reply)
Discussion started by: akash
1 Replies

9. Programming

How to include shell script in C program

hi I want to call a shell script in C program the script is : ssh -t user@remote sh /<remote>home/user/<file_name>.sh and other several commands C program : Call this script and the retrive the task that is been done in <file_name>.sh file can any one tell me how... (5 Replies)
Discussion started by: mridula
5 Replies

10. Shell Programming and Scripting

how to include external files in tcsh

Hello Simple question about tcsh , i like to make external file that some tcsh script will read from him var=="some value" how can i make the include in tcsh files? Thanks (0 Replies)
Discussion started by: umen
0 Replies
Login or Register to Ask a Question