03.02.2014
Kategorie: Linux

Textdatei ohne Kommentare ausgeben


Manchmal ist es sinnvoll zB eine Konfigurationsdatei ohne Kommentare und Leerzeilen anzusehen. Bei den sehr großen Konfiguration von zB der apache httpd.conf oder der freeradius radiusd.conf fällt es im Normalzustand oft schwer Konfigurationen von zwei Servern zu vergleichen oder sogar automatisch mit diff zu vergleichen.

Ein bisschen egrep und grep helfen uns dabei wirklich nur die Zeilen auszugeben die wirkliche Konfiguration beinhalten.

Ausganskonfiguration:

# Multi-language error messages
#Include /etc/httpd/extra/httpd-multilang-errordoc.conf
# Fancy directory listings
#Include /etc/httpd/extra/httpd-autoindex.conf
# Language settings
#Include /etc/httpd/extra/httpd-languages.conf
# User home directories
#Include /etc/httpd/extra/httpd-userdir.conf
# Real-time info on requests and configuration
Include /etc/httpd/extra/httpd-info.conf
# Virtual hosts
#Include /etc/httpd/extra/httpd-vhosts.conf
# Local access to the Apache HTTP Server Manual
#Include /etc/httpd/extra/httpd-manual.conf
# Distributed authoring and versioning (WebDAV)
#Include /etc/httpd/extra/httpd-dav.conf
# Various default settings
#Include /etc/httpd/extra/httpd-default.conf
# Configure mod_proxy_html to understand HTML4/XHTML1

Include /etc/httpd/extra/proxy-html.conf

# Secure (SSL/TLS) connections
#Include /etc/httpd/extra/httpd-ssl.conf
#
# Note: The following must must be present to support
# starting without SSL on platforms with no /dev/random equivalent
# but a statically compiled-in mod_ssl.
#

SSLRandomSeed startup builtin
SSLRandomSeed connect builtin

# Deal with user agents that deliberately violate open standards


BrowserMatch "MSIE 10.0;" bad_DNT



RequestHeader unset DNT env=bad_DNT


Suexec On
Include /etc/httpd/extra/httpd-fcgid.conf
Include /etc/httpd/extra/httpd-mod_security.conf 

Nun können mit einem einfach cat und grep die unnötigen Kommentare und Leerzeilen eliminiert werden.

cat /etc/httpd/httpd.conf | egrep -v "^[^a-z0-9]*#" | grep -v "^$"


Include /etc/httpd/extra/proxy-html.conf


SSLRandomSeed startup builtin
SSLRandomSeed connect builtin


BrowserMatch "MSIE 10.0;" bad_DNT


RequestHeader unset DNT env=bad_DNT

Suexec On
Include /etc/httpd/extra/httpd-fcgid.conf
Include /etc/httpd/extra/httpd-mod_security.conf

Diese "stilisierte Config" kann zB mittels diff von 2 Servern analysiert werden um Unterschiede schnell aufzuzeigen.


 
Telefon:
E-Mail:
Fax:
Web:

+43 2682 24080
office(at)epb.at
+43 2682 205 7700 9963
zum Kontaktformular