[semi-OT] Pretty vs. Useful output
Chip Marshall
chip at 2bithacker.net
Tue Oct 6 14:21:03 EDT 2009
On October 06, 2009, Michael ODonnell sent me the following:
> <rant>
> Grrrrr!! A long-standing source of frustration for me is that people who
> definitely should know better insist on writing code that utters only
> "pretty" outputs instead of useful, parseable info. Yes, it's darling
> and precious that the authors of (say) mdadm, dumpe2fs or /proc/cpuinfo
> spent so much time arranging for their output to be so neatly lined up,
> but it's a fscking PITA for scripts to pluck useful info from within
> that sort of dreck.
>
> If I were king I'd decree that all software be capable of uttering its
> output in a manner that can easily be scanned for items of interest,
> using a format like (say) key=value pairs or maybe (the disappointingly
> oversold) XML. You can always prettify info delivered in a regular
> format but going the other way is, as already mentioned, error-prone
> and inefficient.
> </rant>
This is one of the things that I like about JUNOS. Pretty much any
command in the CLI can be appended with '| display xml' and it'll give
you a reasonably marked up XML version of the command's output.
Makes it very easy to write scripts to connect to a router and collect
information.
root> show system uptime
Current time: 2009-10-06 14:18:30 UTC
System booted: 2009-10-06 14:13:55 UTC (00:04:35 ago)
Protocols started: 2009-10-06 14:14:31 UTC (00:03:59 ago)
Last configured: 2009-05-27 16:35:20 UTC (18w5d 21:43 ago) by root
2:18PM up 5 mins, 2 users, load averages: 0.03, 0.21, 0.13
root> show system uptime | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/8.5R4/junos">
<system-uptime-information xmlns="http://xml.juniper.net/junos/8.5R4/junos">
<current-time>
<date-time junos:seconds="1254838713">2009-10-06 14:18:33 UTC</date-time>
</current-time>
<system-booted-time>
<date-time junos:seconds="1254838435">2009-10-06 14:13:55 UTC</date-time>
<time-length junos:seconds="278">00:04:38</time-length>
</system-booted-time>
<protocols-started-time>
<date-time junos:seconds="1254838471">2009-10-06 14:14:31 UTC</date-time>
<time-length junos:seconds="242">00:04:02</time-length>
</protocols-started-time>
<last-configured-time>
<date-time junos:seconds="1243442120">2009-05-27 16:35:20 UTC</date-time>
<time-length junos:seconds="11396593">18w5d 21:43</time-length>
<user>root</user>
</last-configured-time>
<uptime-information>
<date-time junos:seconds="1254838713">2:18PM</date-time>
<up-time junos:seconds="308">5 mins</up-time>
<active-user-count junos:format="2 users">2</active-user-count>
<load-average-1>0.03</load-average-1>
<load-average-5>0.21</load-average-5>
<load-average-15>0.13</load-average-15>
</uptime-information>
</system-uptime-information>
<cli>
<banner></banner>
</cli>
</rpc-reply>
--
Chip Marshall <chip at 2bithacker.net>
http://weblog.2bithacker.net/ KB1QYW PGP key ID 43C4819E
v4sw5PUhw4/5ln5pr5FOPck4ma4u6FLOw5Xm5l5Ui2e4t4/5ARWb7HKOen6a2Xs5IMr2g6CM
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
Url : http://mail.gnhlug.org/mailman/private/gnhlug-discuss/attachments/20091006/f2d829e5/attachment.bin
More information about the gnhlug-discuss
mailing list