Skip to content

Instantly share code, notes, and snippets.

@edwardgalligan
Created February 2, 2016 16:26
Show Gist options
  • Save edwardgalligan/7865dba609161d21a0a6 to your computer and use it in GitHub Desktop.
Save edwardgalligan/7865dba609161d21a0a6 to your computer and use it in GitHub Desktop.
Generates /etc/hosts entries from Apache vhosts
#!/bin/bash
##
# Usage:
# generaate-hosts.sh 127.0.0.1
#
# Generates:
# 127.0.0.1 vhost1.domain
# 127.0.0.1 vhost1.domainalias1
# etc.
##
if [ "$1" == "" ]; then
echo "Please specify an IP for your hosts file entries"
exit 1
fi
cat ./*.conf | grep 'ServerAlias\|ServerName' | sed 's/Server\(Name\|Alias\)//g ; s/^ *//g ; s/ *$//g' | tr '\n' ' ' | sed "s/^/ /g ; s/ \$//g ; s/ \\([^ ]*\\)/$1 \\1\\n/g"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment