On Tue, Apr 13, 2010 at 11:18:37AM +1000, matthew green wrote: > what do you want to do with these tools? please be specific and > or give examples. 1) In scripts, extract information from property lists: How many cylinders does wd0 have? % drvctl -p wd0 | tail +2 | \ > xmlgrep '//(key/text()="cylinders-per-unit")%integer/value()' 0x12ee9 2) Process web data sources: On the NetBSD blog, what titles has a "Guillaume" written? % ftp -o - http://blog.netbsd.org/tnf/feed/entries/atom | \ > xmlgrep -C '//(entry/author//text()~"Guillaume")/{author|title}' <feed xmlns='http://www.w3.org/2005/Atom'> <entry> <title type='html'>Solutions Linux 2010 - 16-18th March, Paris Porte de Vers ailles</title> <author> <name>Guillaume Lasmayous</name> </author> </entry> </feed> In Champaign-Urbana, Illinois, what is the temperature in degrees Celsius? % ftp -o - http://www.weather.gov/data/current_obs/KCMI.xml | \ > xmlgrep '//temp_c/text()' 25.0 3) Add XML output to existing tools (e.g., ifconfig, netstat). Filter/transform those outputs with xmltools. Just for an example, see attached 'ifconfig -vma' output in human- and in a hypothetical machine-readable format. List interfaces with an address 192.168.x.y: % ifconfig -xvma | \ > xmlgrep -C 'interface//(address and @"value"~"^192\.168\.")' | \ > xmlgrep -v 'interface/*' <interfaces> <interface name='wm0'> </interface> <interface name='fxp0'> </interface> </interfaces> List wm(4) interfaces: % ifconfig -xvma | xmlgrep -C 'interface and @"name"~"^wm[0-9]"' | \ > xmlgrep -v 'interface/*' <interfaces> <interface name='wm0'> </interface> <interface name='wm1'> </interface> </interfaces> Dave -- David Young OJC Technologies dyoung%ojctech.com@localhost Urbana, IL * (217) 278-3933
wm0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 capabilities=2bf80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx,UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Tx,UDP6CSUM_Tx> enabled=2bf80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx,UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Tx,UDP6CSUM_Tx> address: 00:0e:0c:bc:08:cc media: Ethernet autoselect (1000baseT full-duplex,master) status: active supported Ethernet media: media none media 10baseT media 10baseT mediaopt full-duplex media 100baseTX media 100baseTX mediaopt full-duplex media 1000baseT media 1000baseT mediaopt full-duplex media autoselect input: 64664 packets, 47329863 bytes, 2898 multicasts output: 37304 packets, 3994243 bytes, 15 multicasts inet 64.198.255.10 netmask 0xfffffff0 broadcast 64.198.255.15 inet alias 192.168.0.1 netmask 0xffffff00 broadcast 192.168.0.255 inet6 fe80::20e:cff:febc:8cc%wm0 prefixlen 64 scopeid 0x1 inet6 2002:40c6:ff01:1:20e:cff:febc:8cc prefixlen 64 wm1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 capabilities=2bf80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx,UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Tx,UDP6CSUM_Tx> enabled=2bf80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx,UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Tx,UDP6CSUM_Tx> address: 00:0e:0c:bc:01:86 media: Ethernet autoselect (1000baseT full-duplex) status: active supported Ethernet media: media none media 10baseT media 10baseT mediaopt full-duplex media 100baseTX media 100baseTX mediaopt full-duplex media 1000baseT media 1000baseT mediaopt full-duplex media autoselect input: 14914 packets, 1435479 bytes, 14761 multicasts output: 13958 packets, 3626912 bytes, 9 multicasts inet 10.2.2.221 netmask 0xffffff00 broadcast 10.2.2.255 inet6 fe80::20e:cff:febc:186%wm1 prefixlen 64 scopeid 0x2 inet6 2002:40c6:ff01:2:20e:cff:febc:186 prefixlen 64 fxp0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500 address: 00:13:20:5f:8f:cb media: Ethernet none supported Ethernet media: media 10baseT media 10baseT mediaopt full-duplex media 100baseTX media 100baseTX mediaopt full-duplex media autoselect media none input: 139 packets, 15824 bytes, 1 multicast output: 165 packets, 17180 bytes, 18 multicasts inet 192.168.1.101 netmask 0xffffff00 broadcast 192.168.1.255 inet6 fe80::213:20ff:fe5f:8fcb%fxp0 prefixlen 64 scopeid 0x3 lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33192 input: 11 packets, 308 bytes output: 11 packets, 308 bytes inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
Attachment:
ifconfig-vma.xml
Description: application/xml