Add and delete apahce VM in shell script and check whether the VM is normal

Source: Internet
Author: User
1install sendemailtarxvfsendemail-v1.56.tar.gz mvsendEmail-v1.56sendEmail2 add apache Virtual Host shell script: viaddVirtual. sh #! /Bin/bashcat & lt; EOF & gt;/etc/httpd/conf/httpd. conf & lt; VirtualHost *: 80 & gt ;&

1. Install sendEmail

Tar xvf sendEmail-v1.56.tar.gz
Music sendEmail-v1.56 sendEmail

2. Add the apache VM shell script:

Vi addVirtual. sh
#! /Bin/bash
Cat < >/Etc/httpd/conf/httpd. conf

ServerAdmin admin @ $1
DocumentRoot/$1
ServerName $1
ErrorLog logs/$ 1-error_log
CustomLog logs/$ 1-access_log common

EOF

Mkdir/$1
Chmod 755/$1
Service httpd restart

Port = 'netstat-anl | grep 80 | sed-n '1p' | awk' {print $4} '| awk-F:' {print $2 }''
Ip = 'ifconfig eth0 | sed-n 2p | awk '{print $2}' | awk-F: '{print $2 }''
If ["$ port "! = "80"]
Then
/Home/shell/sendEmail-f xxx @ xxx-t xxx @ xxx-s smtp. xxx-u "An error occurred while starting apache !!! "-Xu USER-xp PASSWD-m" $ {ip} apache shutdown, Please contact the administrator"
Fi

Run the script to add a VM:


NameVirtualHost *: 80 #### account opening required ###

[Root @ 3 shell] # sh addVirtual. sh 2.test.com ### 2.test.com is the domain name entered by the user ####

Test:

Add the following in the local hosts file:

192.168.2.5 2.test.com

192.168.2.5 3.test.com

Access 2.test.com #### create a homepage under the generated/2.test.com file ####


######### Using a simple script to configure multiple virtual hosts is fast. The above script can be used with PHP to configure virtual hosts on the PHP page for convenience ....

Address: http://youzao.blog.51cto.com/3946111/741077

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.