- CheckMates
- :
- Products
- :
- Developers
- :
- API / CLI Discussion
- :
- mgmt_cli to delete all objects matching a pattern
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Are you a member of CheckMates?
×- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
mgmt_cli to delete all objects matching a pattern
This came across my mail from an internal source and it's too good not to share.
A small bit of scripting with show-objects and delete-batch-objects can remove all objects (up to the 500 object limit of show-objects) based on a pattern.
mgmt_cli login -u aa -p aaaa > /tmp/sid.txt.$$
mgmt_cli -s /tmp/sid.txt.$$ delete objects-batch objects.1.type group $(mgmt_cli -s /tmp/sid.txt.$$ -f json show objects filter test-group- limit 500 | jq '.objects[].name' | cat -n | sed -r 's/^\s+([0-9]+)/objects.1.list.\1.name/' | tr '\n' ' ')
mgmt_cli -s /tmp/sid.txt.$$ publish
Explanation of commands:
mgmt_cli -s /tmp/sid.txt.$$ delete objects-batch objects.1.type host |
Perform batch delete on the results of the next rows |
$(…) |
Treat the output of the command in parenthesis as command line arguments |
mgmt_cli -s /tmp/sid.txt.$$ -f json show-objects filter test-host- limit 500 |
Get objects containing test-host- |
jq '.objects[].name' |
Get the object names |
cat -n |
Add a line number to each name |
sed -r 's/^\s+([0-9]+)/objects.1.list.\1.name/' |
Replace each line number n with objects.1.list.n.name |
tr '\n' ' ' |
Put all the separate lines together on the same line as input to the delete-objects-batch command |
