The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 03-18-2008
era
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
So something like this?


Code:
#!/bin/bash

domain=${1%.*}
tld=${1#*.}

cat <<HERE
#
# $domain.$tld
#
\$HTTP["host"] =~ "(^|\.)$domain\.$tld\$" {
server.document-root = "/home/$domain/public_html"
server.errorlog = "/var/log/lighttpd/${domain}-error.log"
accesslog.filename = "/var/log/lighttpd/${domain}-access.log"
server.error-handler-404 = "/e404-$domain.php"
}
HERE

Example run:

vnix$ /tmp/htt example.com
#
# example.com
#
$HTTP["host"] =~ "(^|\.)example\.com$" {
server.document-root = "/home/example/public_html"
server.errorlog = "/var/log/lighttpd/exampleerror.log"
accesslog.filename = "/var/log/lighttpd/example-access.log"
server.error-handler-404 = "/e404-example.php"
}

I hope I got all the details right.

You can't really "parse" the variables much, you can perform simple string substitutions like I have but basically it's just $1 $2 $3 and if you need anything fancier, use some external utility.