Skip to content

Commit e95f541

Browse files
authored
Create a Script To Remove Nagios Host Groups (#2804)
* Create a Script To Remove Nagios Host Groups
1 parent ddec392 commit e95f541

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
while read -p "Enter the hostgroup name (Enter to finish) :" -r hostgroup_name
3+
do
4+
if [[ "$hostgroup_name" ]]
5+
then
6+
awk -vhostgroup_name="${hostgroup_name}" '
7+
/^define hostgroup/ { buf=""; addbuf=prtbuf=1 }
8+
addbuf {
9+
buf=(buf $0 ORS)
10+
if ($1=="hostgroup_name" && $2==hostgroup_name) prtbuf=0
11+
if ($1=="}") { addbuf=0; if (prtbuf) printf "%s", buf }
12+
next
13+
}
14+
{ print }
15+
' /usr/local/nagios/etc/objects/hostgroups.cfg > junk.out
16+
mv junk.out /usr/local/nagios/etc/objects/hostgroups.cfg
17+
else
18+
break;
19+
fi
20+
done

0 commit comments

Comments
 (0)