Avatar of Denisvt
Denisvt
 asked on

Editing the Apache config from a bash script: how to append infos to an existing file ?

Hello to all

I am writing a Command Line (Bash) script to automate a blog installation on a Linux server.
So far so good, except that I would like the Apache conf file to be changed too so that I can immediately reload my Web server and have the new hosting functional.
Therefore I must add a few lines at the end of the /etc/apache/httpd.conf file:

<VirtualHost 1.2.3.4.5.6:80>
ServerName myblogsite.fr
DocumentRoot /home/myblogsite.fr/www
(...)
</VirtualHost>

Is it possible to edit that Apache conf directly from my bash script ? I already know how to backup my apache conf, and I currently even already log that required Apache Virtual host info in a file, from which I just copy and paste - see quoted code. What I need is to be able to append that new info exactly at the end of my existing httpd.conf file
Who could point me on how to do that ?

Thanks !
cat <<EOT >${MYPATH}/setupvh_${MYBLOGSITE}.txt
<VirtualHost 1.2.3.4.5.6:80>
ServerName myblogsite.fr
DocumentRoot /home/myblogsite.fr/www
(...)
</VirtualHost>
EOT

Open in new window

Shell ScriptingScripting Languages

Avatar of undefined
Last Comment
Denisvt

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Tintin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Denisvt

ASKER
Well I did consider this, and did try, on a test server with a config backup first I'm glad, because my whole server conf was just replaced by these new infos, and Apache would not even start anymore.
It seems this code deleted the existing file, then starts adding its line (which do get appended) but obviously I need the existing apache conf to be kept !
Thanks.
Denisvt

ASKER
Scratch that, this is the kind of huge mistake a very simple typo can do: I tried my code with the ">" which I guess replaces, while you quoted >> which I guess append to an existing file that does not get replaced...
My bad, thanks for your explanation.
Your help has saved me hundreds of hours of internet surfing.
fblack61