In hostgroup file, i have define lots of hostgroups. I need to remove few of them without manually editing file. Need script or syntax.
I want to search particular on hostgroup_members and delete hostgoup defination of it.
for example.
define hostgroup{
hostgroup_name test
alias test server
hostgroup_members test-server
}
define hostgroup{
hostgroup_name prd
alias Prd server
hostgroup_members prd-server
}
define hostgroup{
hostgroup_name acc
alias acc server
hostgroup_members acc-server
}
for example: suppose i delete prd-server hostgroup_members then my output will be below.
define hostgroup{
hostgroup_name test
alias test server
hostgroup_members test-server
}
define hostgroup{
hostgroup_name acc
alias acc server
hostgroup_members acc-server
}
I have a few to questions pose in response first:-
Is this homework/assignment? There are specific forums for these.
What have you tried so far?
What output/errors do you get?
What OS and version are you using?
What are your preferred tools? (C, shell, perl, awk, etc.)
What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?
There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.
We're all here to learn and getting the relevant information will help us all.
thanks for code. I checked and its working while passing single hostgroups_members name
Can we use same for multiple hostgroups_members to remove by passing file which contain hostgroups_members name.
like putting above code inside for for.
anything need to change in code?
Then you can cycle through them, as demonstrated here
for (i in H) print H
The hosts= needs to be passed with -v at the beginning (not at the end as I did with the host= ) so it is available in the BEGIN section.
Then in the existing code, where there is a reference to host replace it by a for loop through H.
I leave the actual implementation to you.
For clarity you can always use an explicit { block }, for instance
I am not much expert in Awk scripting. I have file where all hostgroup_members entry like below. I want read them in above your code and delete them.
example:
prd-server
acc-server
test-server
app-server
db-server
it will be good and one more request can u explain me code please little bit.