Menu

(Solved) : Write Script Named Genapachevhostsh Ll Wait Finish Lamp Lab Start One Script Automate Proc Q37250506 . . .

write a script named gen_apache_vhost.sh. You’ll haveto wait until you finish the LAMP lab to start this one. Thisscript will automate the process of generating a new virtual hostfor your Apache configuration. All of the steps are straight out ofthe LAMP lab, so refer back to that if you need a reminder of thespecifics of each step. As you saw in that lab, creating a newvirtual host is not all that difficult, but did involve editingseveral files to add entries for the non-SSL and SSL-enabledversions of the website. You also have to modify/etc/hosts to have the new virtual host name listed forthe IP address of the system. Your script must take a singleargument that is the hostname of the new virtual host. It thenhandles all the other details of adding the new virtual host. Hereis the list of major pieces:

  1. Add a VirtualHost entry to the bottom ofhttpd.conf. Be sure that your script generates a backupcopy of the original file in case something gets messed up.
  2. Add a VirtualHost entry to the bottom ofssl.conf. Be sure that your script generates a backup copyof the original file in case something gets messed up.
  3. Create the directory for the new virtual host in/var/www and add a blank index.html file for thevirtual host there.
  4. Modify the IP address line in /etc/hosts to add thenew virtual hostname to the end of the line. Be sure that yourscript generates a backup copy of the original file in casesomething gets messed up.
  5. Restart the httpd.service service.

Clearly you will need to run the script with sudo sinceit will be making many administrative changes to your system. Step4 is the only really complicated step because you have to add newinformation to a line in the middle of the file without destroyingthe rest of the file. You can do this with a loop that reads everyline and prints every line back out, only modifying the output ifit is the IP address line in question. Instead of a loop, you canuse some sed hackery to do it in one step. You’ll have touse back references to make it work which will require a bit ofreading on your own to figure out.

The script should ensure that there is only one argument, thenew virtual hostname, but otherwise there should be no output ifthings worked correctly. Here is an example run:

[user@user eclab]$ sudo./gen_apache_vhost.sh

usage: ./gen_apache_vhost.sh vhost_name

  [user@user eclab]$ sudo./gen_apache_vhost.sh www.test.com

[user@user eclab]$ grep 10.0.2.15/etc/hosts

10.0.2.15 username.comp3100 www.comp3100.privatewww.test.com

[user@user eclab]$

Expert Answer


Answer to write a script named gen_apache_vhost.sh. You’ll have to wait until you finish the LAMP lab to start this one. This sc…

OR