DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 17th May 2008
c0mrade's Avatar
c0mrade c0mrade is offline
Port Guard
 
Join Date: May 2008
Posts: 41
Thanked 0 Times in 0 Posts
Default Adding multiple lines into file

I'm trying to figure out how to write multiple lines at the end of a file.. reason why I need this is I'm hosting couple of website on my machine and it gets boring to write every time same lines
Code:
<VirtualHost yourhostname:80>
    ServerAdmin you@your-domain.com
    ServerName your_ip_address
    DocumentRoot /www
    ErrorLog logs/error_log
    CustomLog logs/access_log combined
</VirtualHost>
Is there a way to write a shell script that will insert these lines at the end of the file... any hints indications how to do it ? Thank you in advance ..
Reply With Quote
  #2   (View Single Post)  
Old 17th May 2008
18Googol2's Avatar
18Googol2 18Googol2 is offline
Real Name: whoami
Spam Deminer
 
Join Date: Apr 2008
Location: pwd
Posts: 283
Thanked 20 Times in 18 Posts
Default

Save the above lines in a file, say AppendedLines, then do:

cat AppendedLines >> VirtualHostFile
__________________
The power of plain text? It can control an entire OS
Reply With Quote
  #3   (View Single Post)  
Old 17th May 2008
c0mrade's Avatar
c0mrade c0mrade is offline
Port Guard
 
Join Date: May 2008
Posts: 41
Thanked 0 Times in 0 Posts
Default

tnx m8 very useful for my cause
Reply With Quote
  #4   (View Single Post)  
Old 7th June 2008
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,141
Thanked 182 Times in 149 Posts
Default

Code:
$ cat update_apache
#!/bin/sh

FILE=httpd.conf

HOSTNAME=$1
YOU=$2
DOMAIN=$3 
IP=$4


cat <<EOF >>${FILE}
<VirtualHost ${HOSTNAME}:80>
    ServerAdmin ${YOU}@${DOMAIN}
    ServerName ${IP}
    DocumentRoot /www
    ErrorLog logs/error_log
    CustomLog logs/access_log combined
</VirtualHost>
EOF

$ sh  update_apache hercules.utp.xnet j65nko pietje_puk.nl 81.00.00.01

$ cat httpd.conf                                                     
<VirtualHost hercules.utp.xnet:80>
    ServerAdmin j65nko@pietje_puk.nl
    ServerName 81.00.00.01
    DocumentRoot /www
    ErrorLog logs/error_log
    CustomLog logs/access_log combined
</VirtualHost>
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #5   (View Single Post)  
Old 7th June 2008
deemon's Avatar
deemon deemon is offline
Fdisk Soldier
 
Join Date: May 2008
Location: Estonia
Posts: 50
Thanked 6 Times in 5 Posts
Default

Here's an idea:
Add "Include etc/apache/virtualhosts" to httpd.conf
and then create a config file (containing only <VirtualHost..>...</VirtualHost>) for each virtualhost in virtualhosts/ directory.
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP read file contents - Maximum file size cksraj Programming 1 21st September 2009 11:38 AM
Deleting lines with certain letters/keywords. bigb89 Programming 4 12th November 2008 11:59 PM
Putting Lines to Together. bigb89 Programming 4 24th September 2008 03:59 AM
Adding a separate /home JMJ_coder NetBSD General 2 29th August 2008 10:45 AM
Having trouble adding 7.0 to GRUB 0.97 Arenlor FreeBSD General 4 26th June 2008 01:02 AM


All times are GMT. The time now is 01:15 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick