LoginSignup
0
0

More than 3 years have passed since last update.

cat実行時にコメントアウト($や#)を非表示にする

Posted at

自分用のメモに近いので解説は雑です。

catでファイル内を表示するとき、コメントアウトが大量にあると見づらいことがある。

結論

cat (filename) |  grep -v -e "^#"

cat zabbix_agentd.conf   |  grep -v -e "^#"

解説

(注:行番号はcatの実行結果に著者が書き足している)

[root@localhost zabbix]# cat zabbix_agentd.conf
  1 # This is a configuration file for Zabbix agent daemon (Unix)
  2 # To get more information about Zabbix, visit http://www.zabbix.com
  3 
  4 ############ GENERAL PARAMETERS #################
  5 
  6 ### Option: PidFile
  7 #       Name of PID file.
  8 #
  9 # Mandatory: no
 10 # Default:
 11 # PidFile=/tmp/zabbix_agentd.pid
 12 
 13 PidFile=/var/run/zabbix/zabbix_agentd.pid
 14 
 15 ### Option: LogType
 16 #       Specifies where log messages are written to:
 17 #               system  - syslog
 18 #               file    - file specified with LogFile parameter
 19 #               console - standard output
 20 #
 21 # Mandatory: no
 22 # Default:
 23 # LogType=file
 24 
 25 ### Option: LogFile
 26 #       Log file name for LogType 'file' parameter.
 27 #
 28 # Mandatory: yes, if LogType is set to file, otherwise no
 29 # Default:
 30 # LogFile=
 31 
 32 LogFile=/var/log/zabbix/zabbix_agentd.log
 33 
 34 ### Option: LogFileSize
 35 #       Maximum size of log file in MB.
 36 #       0 - disable automatic log rotation.
 37 #
 38 # Mandatory: no
 39 # Range: 0-1024
 40 # Default:
 41 # LogFileSize=1
 42 
 43 LogFileSize=0
 44 
 45 ### Option: DebugLevel
 46 #       Specifies debug level:
 47 #       0 - basic information about starting and stopping of Zabbix processes
 48 #       1 - critical information
 49 #       2 - error information
 50 #       3 - warnings
 51 #       4 - for debugging (produces lots of information)
 52 #       5 - extended debugging (produces even more information)
 53 #
 54 # Mandatory: no
 55 # Range: 0-5
 56 # Default:
57 # DebugLevel=3
 58 
 59 ### Option: SourceIP
 60 #       Source IP address for outgoing connections.
 61 #
 62 # Mandatory: no
 63 # Default:
 64 # SourceIP=
 65 
 66 ### Option: EnableRemoteCommands
 67 #       Whether remote commands from Zabbix server are allowed.
 68 #       0 - not allowed
 69 #       1 - allowed
 70 #
 71 # Mandatory: no
 72 # Default:
 73 # EnableRemoteCommands=0
 74 
 75 ### Option: LogRemoteCommands
 76 #       Enable logging of executed shell commands as warnings.
 77 #       0 - disabled
 78 #       1 - enabled
 79 #
 80 # Mandatory: no
 81 # Default:
 82 # LogRemoteCommands=0
 83 
 84 ##### Passive checks related
 85 
 86 ### Option: Server
 87 #       List of comma delimited IP addresses, optionally in CIDR notation, or DNS names of Zabbix servers and Zabbix proxies.
 88 #       Incoming connections will be accepted only from the hosts listed here.
 89 #       If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally
 90 #       and '::/0' will allow any IPv4 or IPv6 address.
 91 #       '0.0.0.0/0' can be used to allow any IPv4 address.
 92 #       Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com
 93 #
 94 # Mandatory: yes, if StartAgents is not explicitly set to 0
 95 # Default:
 96 # Server=
 97 
 98 #Server=127.0.0.1
 99 Server=114.514.191.9
100 
101 ### Option: ListenPort
102 #       Agent will listen on this port for connections from the server.
103 #
104 # Mandatory: no
105 # Range: 1024-32767
106 # Default:
107 # ListenPort=10050
108 
109 ### Option: ListenIP
110 #       List of comma delimited IP addresses that the agent should listen on.
111 #       First IP address is sent to Zabbix server if connecting to it to retrieve list of active checks.
112 #
113 # Mandatory: no
114 # Default:
115 # ListenIP=0.0.0.0
116 
117 ### Option: StartAgents
118 #       Number of pre-forked instances of zabbix_agentd that process passive checks.
119 #       If set to 0, disables passive checks and the agent will not listen on any TCP port.
120 #
121 # Mandatory: no
122 # Range: 0-100
123 # Default:
124 # StartAgents=3
125 
126 ##### Active checks related
127 
128 ### Option: ServerActive
129 #       List of comma delimited IP:port (or DNS name:port) pairs of Zabbix servers and Zabbix proxies for active checks.
130 #       If port is not specified, default port is used.
131 #       IPv6 addresses must be enclosed in square brackets if port for that host is specified.
132 #       If port is not specified, square brackets for IPv6 addresses are optional.
133 #       If this parameter is not specified, active checks are disabled.
134 #       Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1]
135 #
136 # Mandatory: no
137 # Default:
138 # ServerActive=
139 
140 #ServerActive=127.0.0.1
141 ServerActive=114.514.191.9
142 
143 ### Option: Hostname
144 #       Unique, case sensitive hostname.
145 #       Required for active checks and must match hostname as configured on the server.
146 #       Value is acquired from HostnameItem if undefined.
147 #
148 # Mandatory: no
149 # Default:
150 # Hostname=
151 
152 Hostname=Zabbix server
153 
154 ### Option: HostnameItem
155 #       Item used for generating Hostname if it is undefined. Ignored if Hostname is defined.
156 #       Does not support UserParameters or aliases.
157 #
158 # Mandatory: no
159 # Default:
160 # HostnameItem=system.hostname
161 
162 ### Option: HostMetadata
163 #       Optional parameter that defines host metadata.
164 #       Host metadata is used at host auto-registration process.
165 #       An agent will issue an error and not start if the value is over limit of 255 characters.
166 #       If not defined, value will be acquired from HostMetadataItem.
167 #
168 # Mandatory: no
169 # Range: 0-255 characters
170 # Default:
171 # HostMetadata=
172 
173 ### Option: HostMetadataItem
174 #       Optional parameter that defines an item used for getting host metadata.
175 #       Host metadata is used at host auto-registration process.
176 #       During an auto-registration request an agent will log a warning message if
177 #       the value returned by specified item is over limit of 255 characters.
178 #       This option is only used when HostMetadata is not defined.
179 #
180 # Mandatory: no
181 # Default:
182 # HostMetadataItem=
183 
184 ### Option: RefreshActiveChecks
185 #       How often list of active checks is refreshed, in seconds.
186 #
187 # Mandatory: no
188 # Range: 60-3600
189 # Default:
190 # RefreshActiveChecks=120
191 
192 ### Option: BufferSend
193 #       Do not keep data longer than N seconds in buffer.
194 #
195 # Mandatory: no
196 # Range: 1-3600
197 # Default:
198 # BufferSend=5
199 
200 ### Option: BufferSize
201 #       Maximum number of values in a memory buffer. The agent will send
202 #       all collected data to Zabbix Server or Proxy if the buffer is full.
203 #
204 # Mandatory: no
205 # Range: 2-65535
206 # Default:
207 # BufferSize=100
208 
209 ### Option: MaxLinesPerSecond
210 #       Maximum number of new lines the agent will send per second to Zabbix Server
211 #       or Proxy processing 'log' and 'logrt' active checks.
212 #       The provided value will be overridden by the parameter 'maxlines',
213 #       provided in 'log' or 'logrt' item keys.
214 #
215 # Mandatory: no
216 # Range: 1-1000
217 # Default:
218 # MaxLinesPerSecond=20
219 
220 ############ ADVANCED PARAMETERS #################
221 
222 ### Option: Alias
223 #       Sets an alias for an item key. It can be used to substitute long and complex item key with a smaller and simpler one.
224 #       Multiple Alias parameters may be present. Multiple parameters with the same Alias key are not allowed.
225 #       Different Alias keys may reference the same item key.
226 #       For example, to retrieve the ID of user 'zabbix':
227 #       Alias=zabbix.userid:vfs.file.regexp[/etc/passwd,^zabbix:.:([0-9]+),,,,\1]
228 #       Now shorthand key zabbix.userid may be used to retrieve data.
229 #       Aliases can be used in HostMetadataItem but not in HostnameItem parameters.
230 #
231 # Mandatory: no
232 # Range:
233 # Default:
234 
235 ### Option: Timeout
236 #       Spend no more than Timeout seconds on processing
237 #
238 # Mandatory: no
239 # Range: 1-30
240 # Default:
241 # Timeout=3
242 
243 ### Option: AllowRoot
244 #       Allow the agent to run as 'root'. If disabled and the agent is started by 'root', the agent
245 #       will try to switch to the user specified by the User configuration option instead.
246 #       Has no effect if started under a regular user.
247 #       0 - do not allow
248 #       1 - allow
249 #
250 # Mandatory: no
251 # Default:
252 # AllowRoot=0
253 
254 ### Option: User
255 #       Drop privileges to a specific, existing user on the system.
256 #       Only has effect if run as 'root' and AllowRoot is disabled.
257 #
258 # Mandatory: no
259 # Default:
260 # User=zabbix
261 
262 ### Option: Include
263 #       You may include individual files or all files in a directory in the configuration file.
264 #       Installing Zabbix will create include directory in /usr/local/etc, unless modified during the compile time.
265 #
266 # Mandatory: no
267 # Default:
268 # Include=
269 
270 Include=/etc/zabbix/zabbix_agentd.d/*.conf
271 
272 # Include=/usr/local/etc/zabbix_agentd.userparams.conf
273 # Include=/usr/local/etc/zabbix_agentd.conf.d/
274 # Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf
275 
276 ####### USER-DEFINED MONITORED PARAMETERS #######
277 
278 ### Option: UnsafeUserParameters
279 #       Allow all characters to be passed in arguments to user-defined parameters.
280 #       The following characters are not allowed:
281 #       \ ' " ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @
282 #       Additionally, newline characters are not allowed.
283 #       0 - do not allow
284 #       1 - allow
285 #
286 # Mandatory: no
287 # Range: 0-1
288 # Default:
289 # UnsafeUserParameters=0
290 
291 ### Option: UserParameter
292 #       User-defined parameter to monitor. There can be several user-defined parameters.
293 #       Format: UserParameter=<key>,<shell command>
294 #       See 'zabbix_agentd' directory for examples.
295 #
296 # Mandatory: no
297 # Default:
298 # UserParameter=
299 
300 ####### LOADABLE MODULES #######
301 
302 ### Option: LoadModulePath
303 #       Full path to location of agent modules.
304 #       Default depends on compilation options.
305 #       To see the default path run command "zabbix_agentd --help".
306 #
307 # Mandatory: no
308 # Default:
309 # LoadModulePath=${libdir}/modules
310 
311 ### Option: LoadModule
312 #       Module to load at agent startup. Modules are used to extend functionality of the agent.
313 #       Formats:
314 #               LoadModule=<module.so>
315 #               LoadModule=<path/module.so>
316 #               LoadModule=</abs_path/module.so>
317 #       Either the module must be located in directory specified by LoadModulePath or the path must precede the module name.
318 #       If the preceding path is absolute (starts with '/') then LoadModulePath is ignored.
319 #       It is allowed to include multiple LoadModule parameters.
320 #
321 # Mandatory: no
322 # Default:
323 # LoadModule=
324 
325 ####### TLS-RELATED PARAMETERS #######
326 
327 ### Option: TLSConnect
328 #       How the agent should connect to server or proxy. Used for active checks.
329 #       Only one value can be specified:
330 #               unencrypted - connect without encryption
331 #               psk         - connect using TLS and a pre-shared key
332 #               cert        - connect using TLS and a certificate
333 #
334 # Mandatory: yes, if TLS certificate or PSK parameters are defined (even for 'unencrypted' connection)
335 # Default:
336 # TLSConnect=unencrypted
337 
338 ### Option: TLSAccept
339 #       What incoming connections to accept.
340 #       Multiple values can be specified, separated by comma:
341 #               unencrypted - accept connections without encryption
342 #               psk         - accept connections secured with TLS and a pre-shared key
343 #               cert        - accept connections secured with TLS and a certificate
344 #
345 # Mandatory: yes, if TLS certificate or PSK parameters are defined (even for 'unencrypted' connection)
346 # Default:
347 # TLSAccept=unencrypted
348 
349 TLSConnect=psk
350 TLSAccept=psk
351 TLSPSKFile=/home/zabbix_agentd.psk
352 TLSPSKIdentity=1145141919
353 
317 #       Either the module must be located in directory specified by LoadModulePath or the path must precede the module name.
318 #       If the preceding path is absolute (starts with '/') then LoadModulePath is ignored.
319 #       It is allowed to include multiple LoadModule parameters.
320 #
321 # Mandatory: no
322 # Default:
323 # LoadModule=
324 
325 ####### TLS-RELATED PARAMETERS #######
326 
327 ### Option: TLSConnect
328 #       How the agent should connect to server or proxy. Used for active checks.
329 #       Only one value can be specified:
330 #               unencrypted - connect without encryption
331 #               psk         - connect using TLS and a pre-shared key
332 #               cert        - connect using TLS and a certificate
333 #
334 # Mandatory: yes, if TLS certificate or PSK parameters are defined (even for 'unencrypted' connection)
335 # Default:
336 # TLSConnect=unencrypted
337 
338 ### Option: TLSAccept
339 #       What incoming connections to accept.
340 #       Multiple values can be specified, separated by comma:
341 #               unencrypted - accept connections without encryption
342 #               psk         - accept connections secured with TLS and a pre-shared key
343 #               cert        - accept connections secured with TLS and a certificate
344 #
345 # Mandatory: yes, if TLS certificate or PSK parameters are defined (even for 'unencrypted' connection)
346 # Default:
347 # TLSAccept=unencrypted
348 
349 TLSConnect=psk
350 TLSAccept=psk
351 TLSPSKFile=/home/zabbix_agentd.psk
352 TLSPSKIdentity=1145141919
353 
354 ### Option: TLSCAFile
355 #       Full pathname of a file containing the top-level CA(s) certificates for
356 #       peer certificate verification.
357 #
358 # Mandatory: no
359 # Default:
360 # TLSCAFile=
361 
362 ### Option: TLSCRLFile
363 #       Full pathname of a file containing revoked certificates.
364 #
365 # Mandatory: no
366 # Default:
367 # TLSCRLFile=
368 
369 ### Option: TLSServerCertIssuer
370 #               Allowed server certificate issuer.
371 #
372 # Mandatory: no
373 # Default:
374 # TLSServerCertIssuer=
375 
376 ### Option: TLSServerCertSubject
377 #               Allowed server certificate subject.
378 #
379 # Mandatory: no
380 # Default:
381 # TLSServerCertSubject=
382 
383 ### Option: TLSCertFile
384 #       Full pathname of a file containing the agent certificate or certificate chain.
385 #
386 # Mandatory: no
387 # Default:
388 # TLSCertFile=
389 
390 ### Option: TLSKeyFile
391 #       Full pathname of a file containing the agent private key.
392 #
393 # Mandatory: no
394 # Default:
395 # TLSKeyFile=
396 
397 ### Option: TLSPSKIdentity
398 #       Unique, case sensitive string used to identify the pre-shared key.
399 #
400 # Mandatory: no
401 # Default:
402 # TLSPSKIdentity=
403 
404 ### Option: TLSPSKFile
405 #       Full pathname of a file containing the pre-shared key.
406 #
407 # Mandatory: no
408 # Default:
409 # TLSPSKFile=

このように「実際には約400行あるが、どこが有効な行なのかがパッと見て不明である。」という状況がある。

解決方法

つまり#から始まる行が邪魔なので

[root@localhost zabbix]# cat zabbix_agentd.conf | grep -v -e "^#"

[root@localhost zabbix]# cat zabbix_agentd.conf | grep -v -e "^#"
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=114.514.191.9
ServerActive=114.514.191.9
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agentd.d/*.conf
TLSConnect=psk
TLSAccept=psk
TLSPSKFile=/home/zabbix_agentd.psk
TLSPSKIdentity=1145141919

複数ある場合

-e "「文字」" を複数連ねることで複数指定可能。

例:#Tから始まる行を取り除く

[root@localhost zabbix]# cat zabbix_agentd.conf | grep -v -e "^#" -e "^$"

cat zabbix_agentd.conf | grep -v -e "^#" -e "^T"
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=114.514.191.9
ServerActive=114.514.191.9
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agentd.d/*.conf
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0