{"id":1675,"date":"2017-06-30T15:55:17","date_gmt":"2017-06-30T19:55:17","guid":{"rendered":"http:\/\/mossiso.com\/?p=1675"},"modified":"2017-06-30T15:55:17","modified_gmt":"2017-06-30T19:55:17","slug":"grab-all-of-the-domain-names-in-apache-host-file","status":"publish","type":"post","link":"https:\/\/mossiso.com\/2017\/06\/30\/grab-all-of-the-domain-names-in-apache-host-file\/","title":{"rendered":"Grab all of the domain names in Apache host file"},"content":{"rendered":"<p>Quick script I whipped up today to grab all of the domain names on a server.<\/p>\n<pre class=\"lang:sh decode:true\">#!\/bin\/bash\r\n\r\nif [ -e alldomains ]\r\nthen\r\n  rm alldomains\r\nfi\r\n\r\nalldomains=( $(find \/etc\/httpd\/conf.vhosts\/ -name *.conf) )\r\n\r\nfor domain in ${alldomains[*]}\r\ndo\r\n  cat $domain | egrep \"ServerName|ServerAlias\" | egrep -v \"#\" | sed -e 's|ServerName||' -e 's|ServerAlias||' -e 's|www.||' -e 's|:80||' | tr -s ' ' '\\n' | tr -d ' ' | sed -e '\/^\\s*$\/d' &gt;&gt; alldomains\r\ndone\r\n\r\nsort alldomains | uniq | sort -o alldomains<\/pre>\n<p>&nbsp;<\/p>\n<p>This gets all of the domains from ServerName and ServerAlias lines, takes out all of the white space and empty lines, and creates a file with just a list of the unique domain names.<\/p>\n<p>This accounts for subdomains that use &#8216;www&#8217; or have port :80 on the end.<\/p>\n<p>For instance, www.somedomain.com and somedomain.com are the same, so the script takes out the &#8216;www.&#8217; which leaves to copies of somedomain.com, which it then deletes one of them in the final output to the file. The same for &#8216;:80&#8217;.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick script I whipped up today to grab all of the domain names on a server. #!\/bin\/bash if [ -e alldomains ] then rm alldomains fi alldomains=( $(find \/etc\/httpd\/conf.vhosts\/ -name *.conf) ) for domain in ${alldomains[*]} do cat $domain | egrep &#8220;ServerName|ServerAlias&#8221; | egrep -v &#8220;#&#8221; | sed -e &#8216;s|ServerName||&#8217; -e &#8216;s|ServerAlias||&#8217; -e &#8216;s|www.||&#8217; -e &hellip; <a href=\"https:\/\/mossiso.com\/2017\/06\/30\/grab-all-of-the-domain-names-in-apache-host-file\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Grab all of the domain names in Apache host file<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"aside","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[3,259,167,170],"tags":[20,236,292,223],"class_list":["post-1675","post","type-post","status-publish","format-aside","hentry","category-coding","category-systems-administration-technical","category-technical","category-websites","tag-apache","tag-bash","tag-devops","tag-systems-administration","post_format-post-format-aside"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9wosP-r1","_links":{"self":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/1675"}],"collection":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/comments?post=1675"}],"version-history":[{"count":6,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/1675\/revisions"}],"predecessor-version":[{"id":1681,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/1675\/revisions\/1681"}],"wp:attachment":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/media?parent=1675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/categories?post=1675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/tags?post=1675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}