Peter Taps
2010-Dec-06 21:40 UTC
[zfs-discuss] How to safely parse "zpool get all" output?
Folks, Command "zpool get all poolName" does not provide any option to generate parsable output. The returned output contains 4 fields - name, property, value and source. These fields seems to be separated by spaces. I am wondering if it is safe to assume that there are no spaces in the field values. If this is the case, I can split the output across spaces. Thank you in advance for your help. Regards, Peter -- This message posted from opensolaris.org
Roy Sigurd Karlsbakk
2010-Dec-06 22:07 UTC
[zfs-discuss] How to safely parse "zpool get all" output?
> Command "zpool get all poolName" does not provide any option to > generate parsable output. The returned output contains 4 fields - > name, property, value and source. These fields seems to be separated > by spaces. I am wondering if it is safe to assume that there are no > spaces in the field values. If this is the case, I can split the > output across spaces.A little fiddling with perl will get you right on track Vennlige hilsener / Best regards roy -- Roy Sigurd Karlsbakk (+47) 97542685 roy at karlsbakk.net http://blogg.karlsbakk.net/ -- I all pedagogikk er det essensielt at pensum presenteres intelligibelt. Det er et element?rt imperativ for alle pedagoger ? unng? eksessiv anvendelse av idiomer med fremmed opprinnelse. I de fleste tilfeller eksisterer adekvate og relevante synonymer p? norsk.
Roy Sigurd Karlsbakk
2010-Dec-06 22:13 UTC
[zfs-discuss] How to safely parse "zpool get all" output?
> Command "zpool get all poolName" does not provide any option to > generate parsable output. The returned output contains 4 fields - > name, property, value and source. These fields seems to be separated > by spaces. I am wondering if it is safe to assume that there are no > spaces in the field values. If this is the case, I can split the > output across spaces.For instance #!/usr/bin/perl # vim:ts=4:sw=4:si my $pool = "mimedata"; open F,"zpool get all $pool|" || die "wtf?"; while (<F>) { if (/^$pool\s+(\w+)\s+(\w+)/) { my $key = $1; my $value = $2; print "$key => $value\n"; } } Vennlige hilsener / Best regards roy -- Roy Sigurd Karlsbakk (+47) 97542685 roy at karlsbakk.net http://blogg.karlsbakk.net/ -- I all pedagogikk er det essensielt at pensum presenteres intelligibelt. Det er et element?rt imperativ for alle pedagoger ? unng? eksessiv anvendelse av idiomer med fremmed opprinnelse. I de fleste tilfeller eksisterer adekvate og relevante synonymer p? norsk.
Peter Taps
2010-Dec-06 23:07 UTC
[zfs-discuss] How to safely parse "zpool get all" output?
Hi, Thank you for your help. I actually had the script working. However, I just wanted to make sure that spaces are not permitted within the field value itself. Otherwise, the regular expression would break. Regards, Peter -- This message posted from opensolaris.org
Richard Elling
2010-Dec-06 23:55 UTC
[zfs-discuss] How to safely parse "zpool get all" output?
Spaces are permitted in the value field. We (myself and Nexenta) use them extensively. -- richard On Dec 6, 2010, at 1:40 PM, Peter Taps wrote:> Folks, > > Command "zpool get all poolName" does not provide any option to generate parsable output. The returned output contains 4 fields - name, property, value and source. These fields seems to be separated by spaces. I am wondering if it is safe to assume that there are no spaces in the field values. If this is the case, I can split the output across spaces. > > Thank you in advance for your help. > > Regards, > Peter > -- > This message posted from opensolaris.org > _______________________________________________ > zfs-discuss mailing list > zfs-discuss at opensolaris.org > http://mail.opensolaris.org/mailman/listinfo/zfs-discuss