Eliminating Comment Lines in a Config File

by Mike on January 10, 2009

in Web Server

Reviewing the Settings for NRPE

Here is a command that you can run that will eliminate all of the comments out of a configuration file.  The example is the nrpe.cfg file used with Nagios plugins.

The command egrep will look for lines that begin with “#” or “$” and then because it is using the “-v” which means to invert match, it will not show the commented lines.  This is a handy tool for reviewing configuration files that are often overwhelming in trying to find the information you want.  It is piped to less so that you can move up and down in the results.

egrep -v ‘^#|^$’ the_path_to_the_config_file | less

egrep -v ‘^#|^$’ nrpe.cfg | less

log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=192.168.4.26

dont_blame_nrpe=0
debug=0
command_timeout=60
connection_timeout=300
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
command[check_sda3]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda3
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_memory]=/usr/local/nagios/libexec/check_memory -w 20 -c 10
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 95 -c 90
command[check_hd]=/usr/local/nagios/libexec/check_hdtemp /dev/sda 50 60

Previous post:

Next post: