Two Spoonfuls of Sugar

I was asked the other day to compare 2 queue managers in different environments (say, for the sake of argument, “test” and “pre-prod”) and to create the queues missing from “pre-prod”, and to delete the ones missing from “test”. I started going through the queue managers to list the missing and extra queues manually, and then I realised that there were many more queues to be updated than expected, so it had to scripted.

This is a classic “compare two lists” exercise, and I thought my new-found Ruby knowledge might come in handy.

Listing the queues for a given queue manager is nothing complicated:

$ echo "display qlocal(*)" | runmqsc queue.manager.test | grep QUEUE > tst.txt
$ echo "display qlocal(*)" | runmqsc queue.manager.pre | grep QUEUE > pre.txt

Finding the queues to be created and deleted is basically a subtraction between the 2 sets. And that’s where using Ruby makes things ridiculously easy:

tst = []
pre = []
IO.readlines("tst.txt").each{ |queue| tst << queue.to_s.chomp }
IO.readlines("pre.txt").each{ |queue| pre << queue.to_s.chomp }
puts "Queues to be created"
puts tst-pre
puts ""
puts "Queues to be deleted"
puts pre-tst

And you might wonder: why not do it all in Ruby? Ok. So if you like it full of syntactic sugar, the whole thing could be packed into a single script, and that would give something like:

tst = `echo "display qlocal(*)" | runmqsc queue.manager.test | grep QUEUE`.split(/\n/)
pre = `echo "display qlocal(*)" | runmqsc queue.manager.pre | grep QUEUE`.split(/\n/)
puts "Queues to be created"
(tst-pre).each{ |elt| puts elt.gsub(/\s*QUEUE\(([^\)]+)\)/, 'DEFINE QLOCAL(\1)') }
puts ""
puts "Queues to be deleted"
(pre-tst).each{ |elt| puts elt.gsub(/\s*QUEUE\(([^\)]+)\)/, 'DELETE QLOCAL(\1)') }

Deadly. Don’t forget to brush your teeth.

 
---

Comment

your_ip_is_blacklisted_by sbl.spamhaus.org

---