Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
PhoneBoy
Admin
Admin

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

 

 

0 Kudos
0 Replies

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events