LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 01-09-2008, 05:11 AM   #1
sinister1
Member
 
Registered: Jul 2007
Posts: 70

Rep: Reputation: 15
Add multiple lines to sites-available automatic


Hai THere,

I am making a script that will automate the steps for adding a domain to a linux webserver.

How can i add multiple lines in a file with a variable in it.

The script works like this:

run script;
scripts asks which domain:
user enters domain;
The directories and symbolic links are made;
the user rights are set;
***NEED TO ADD BELOW LINES TO sites-available/$DOMAIN***
<VirtualHost ip address>
DocumentRoot /export/www/$DOMAIN/html
php_flag log_errors on
php_value error_log /export/www/$DOMAIN/logs/php_error.log
ServerName $DOMAIN
ErrorLog /export/www/$DOMAIN/logs/error.log
CustomLog /export/www/$DOMAIN/logs/access.log "combined"
HostNameLookups off
</VirtualHost>

How can i do this part? I can add them one at a time but can i put the whole text in a variable?

Thank you in advance.

Grt.
 
Old 01-09-2008, 05:46 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,260
Blog Entries: 54

Rep: Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841
Two stupid examples.

A function with tab formatted VHost output:
addVH() { echo -en "\n<VirtualHost ip address>\n\tDocumentRoot /export/www/$1/html\n\tphp_flag log_errors on\n\tphp_value error_log /export/www/$1/logs/php_error.log\n\tServerName $1\n\tErrorLog /export/www/$1/logs/error.log\n\tCustomLog /export/www/$1/logs/access.log \"combined\"\n\tHostNameLookups off\n</VirtualHost>\n"; }
It takes domain name as single arg so you can do "addVH someDomain >> /some/config/file".

A "here" document:
Code:
DOMAIN="microsoft.com"
cat << EOL >> /some/config/file
<VirtualHost ip address>
 DocumentRoot /export/www/$DOMAIN/html
 php_flag log_errors on
 php_value error_log /export/www/$DOMAIN/logs/php_error.log
 ServerName $DOMAIN
 ErrorLog /export/www/$DOMAIN/logs/error.log
 CustomLog /export/www/$DOMAIN/logs/access.log "combined"
 HostNameLookups off
</VirtualHost>
EOL
Functions are good for repetitive things. Since they group code in blocks make code readable as well, use local variables and as bonus you get $FUNCNAME which comes in handy when reporting errors or progress (like 'echo "${0//*\//}: FATAL in ${FUNCNAME}()"').
 
  


Reply

Tags
automatic, lines, multiple


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 05:08 PM
Bind configuration for multiple sub-domains on multiple sites JF1980 Linux - Networking 3 08-31-2006 01:28 PM
PFTP help (how to add sites and more) Jimichel Linux - Software 1 04-16-2005 08:41 AM
Multiple Apache Sites, on Multiple IP's, on Same Box?? RickyJ Linux - General 1 06-19-2003 10:55 AM
Multiple Apache Sites, on Multiple IP's, on Same Box?? RickyJ Linux - Software 0 06-19-2003 09:50 AM


All times are GMT -5. The time now is 12:28 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration