Perlovský skript pro výpis /etc/fstab v XML formátu.
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 07 May 2012 14:05:26 +0200
changeset 17a594ee3c93a5
parent 16 131d2652b241
child 18 b356e7c9211f
Perlovský skript pro výpis /etc/fstab v XML formátu.
perl/perl-fstab.pl
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/perl/perl-fstab.pl	Mon May 07 14:05:26 2012 +0200
     1.3 @@ -0,0 +1,48 @@
     1.4 +#!/usr/bin/perl
     1.5 +
     1.6 +# Vypíše /etc/fstab ve formě XML souboru.
     1.7 +# 
     1.8 +# Závislosti:
     1.9 +#	aptitude install libxml-writer-perl
    1.10 +
    1.11 +use strict;
    1.12 +use warnings;
    1.13 +
    1.14 +use IO::String;
    1.15 +use XML::Writer;
    1.16 +
    1.17 +my $xml;
    1.18 +my $output = new IO::String->new($xml);
    1.19 +my $writer = new XML::Writer(	OUTPUT => $output,
    1.20 +								DATA_MODE => 1,
    1.21 +								DATA_INDENT => "	");
    1.22 +
    1.23 +$writer->xmlDecl("UTF-8");
    1.24 +$writer->startTag("fstab");
    1.25 +
    1.26 +my $fstab;
    1.27 +open($fstab, "<", "/etc/fstab");
    1.28 +while (my $r = <$fstab>) {
    1.29 +	if ($r !~ /^\x23/ && $r =~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/) {
    1.30 +		$writer->startTag("bod");
    1.31 +		$writer->dataElement("zařízení", "$1");
    1.32 +		$writer->dataElement("přípojnýBod", "$2");
    1.33 +		$writer->dataElement("souborovýSystém", "$3");
    1.34 +
    1.35 +		$writer->startTag("volby");
    1.36 +		my @volby = split(",", $4);
    1.37 +		foreach my $volba (@volby) {
    1.38 +			$writer->dataElement("volba", "$volba");
    1.39 +		}
    1.40 +		$writer->endTag();
    1.41 +
    1.42 +		$writer->dataElement("dump", "$5");
    1.43 +		$writer->dataElement("pass", "$6");
    1.44 +		$writer->endTag();
    1.45 +	}
    1.46 +}
    1.47 +
    1.48 +$writer->endTag();
    1.49 +print $xml;
    1.50 +print "\n";
    1.51 +