Last active
November 15, 2023 16:16
-
-
Save weatheredwatcher/44868f5db74e8916017a to your computer and use it in GitHub Desktop.
A python script for creating vhost files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys, getopt | |
def main(argv): | |
server = '' | |
path = '' | |
try: | |
opts, args = getopt.getopt(argv, "hs:p:", ["server=", "path="] ) | |
except getopt.GetoptError: | |
print 'Usage: vhost_writer.py -s <servername> -p <pathname>' | |
sys.exit(2) | |
for opt, arg in opts: | |
if opt == '-h': | |
print 'Usage: vhost_writer.py -s <servername> -p <pathname>' | |
sys.exit() | |
elif opt in ("-s", "--server"): | |
server = arg | |
elif opt in ("-p", "--path"): | |
path = arg | |
print f""" | |
<VirtualHost *:80> | |
ServerName {server} | |
ServerAlias www.{server} | |
DocumentRoot /var/www/{path} | |
<Directory /var/www/{path} | |
Options -Indexes FollowSymLinks -MultiViews | |
AllowOverride All | |
</Directory> | |
CustomLog /var/log/httpd/{server}-access.log combined | |
ErrorLog /var/log/httpd/{server}-error.log | |
# Possible values include: debug, info, notice, warn, error, crit, | |
# alert, emerg. | |
</VirtualHost> | |
""" | |
if __name__ == "__main__": | |
main(sys.argv[1:]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to use f-strings