Simple JSON parsing from Bash using Python

Have a Bash command you like to use a lot but need to parse some JSON data from another script? Here’s a quick inline Python command you might find helpful:

COUNT=`jscript.sh|python -c "import json; import sys;
  data=json.load(sys.stdin); print data['count']"`

Just substitute the name of your other shell script (jscript.sh) and the JSON index (count) as appropriate and you’re all set!

Oh, and of course, join the 2 preformatted lines above also – these are just split because by WordPress theme was truncating the single-line version.

Solaris CoolStack 1.3 released

CoolStack is a collection of some of the most commonly used open source applications optimized for the Sun Solaris platform. The latest version of this software suite, Cool Stack 1.3, has just been released. Here is a brief overview:

Notable Additions

  • Python 2.5.2
  • Nginx 0.6.31
  • New Apache modules including mod_python, mod_ruby, mod_dtrace etc.

Updated Versions

  • Apache 2.28
  • Tomcat 5.5.26
  • MySQL 5.1.24
  • PHP 5.2.6
  • Memcached 1.2.5
  • Ruby 1.8.6p114 with Ruby Gems 1.1.1 and Rails 2.0.2

Other Enhancements

  • Ruby performance improvements in the order of 20-30% (with a further 8-15% coming down the line when Ruby 1.8.7 is released)
  • Better support for installing Ruby Gems that require native compilation on SPARC systems

The addition of Nginx an Python support along with the performance improvements in Ruby as well as the additional Apache modules are all very useful additions and have yet again come at just the right time for our organisation. Well done to Shanti and his team for providing almost exactly everything we were hoping for in this release, again!

To script or not to script

In an interesting article on the merits (or not) of scripting languages, James Turner outlines where some of their strengths and weaknesses lie. He uses Perl as the example in this instance but on reading the article I found that many of the pros and cons readily apply to most other scripting languages I’ve used (Tcl, Python, Bash, Sh).

In particular, his comments about them being strong on cross-platform support and weak on performance-related applications definitely ring true from my past experiences with Tcl/Tk. However, one point that he did not make, which I feel is definitely one of scripting languages’ stronger points, is in the area of custom testing and debugging, in the context of prototype product design and integration.

The likes of Perl, Python and/or Tcl really can enable you to glue together some pretty compelling, custom-made testing utilities, often without the need for complicated frameworks or other plugins. In particular, the ability to create your own extensions (using C or even SWIG) can make for some pretty powerful, tailor-made manufacturing test tools (trust me, I’ve been there!).

Of course this may not suit everyone’s needs, and there will be those that will opt for off-the-shelf products that do similar. However, if you are dealing with a newly designed product or hardware appliance featuring custom firmware not seen before, that needs to run on several different platforms, then a decent scripting language will most definitely be your friend.

Source: CIO.com