I have lots of Nagios configuration files like the one below in a directory, and I need to remove a host from monitoring.

define host{
    host_name nmo
    use aix-server
    hostgroups +bu-automotive-aerospace-prd,screen-automotive-aerospace-prd2

What normally I do to remove a host from monitoring is this:

1) Find the host configuration file:

root@XXXXX:/home/rakesh/host_decom# grep -irow nmo hosts*

2) Comment the configuration lines:

vim hosts-automotive.cfg

enter image description here

3) Save the file, and the task has been completed.

How can I automate this process using a script?

  • Please don't post images of text. – Tomasz Mar 1 at 2:23
  • Do you want me send the text? – Rakesh Kumar Mar 1 at 2:55
  • Apologies, if you found my words rude. I am new in Regular expressions and trying just to replace a specific configuration with # comments – Rakesh Kumar Mar 1 at 3:21
  • I am able to extract the configuration using - perl -0777 -ne '/([^\n]*{[^}]*(hostname)[^}]*})/ && print "$1\n"' file_name Now just trying to replace it with # comment in each line – Rakesh Kumar Mar 1 at 3:24
  • @RakeshKumar What Tomasz means is that you should replace the screenshots in your question with the actual text content. There are several reasons for this, such as images being unfriendly for mobile devices. – Haxiel Mar 1 at 3:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.