perl/perl-fstab.pl
author František Kučera <franta-hg@frantovo.cz>
Sat Sep 22 22:28:35 2012 +0200 (2012-09-22)
changeset 18 b356e7c9211f
permissions -rwxr-xr-x
vylepšený (q)makefile
     1 #!/usr/bin/perl
     2 
     3 # Vypíše /etc/fstab ve formě XML souboru.
     4 # 
     5 # Závislosti:
     6 #	aptitude install libxml-writer-perl
     7 
     8 use strict;
     9 use warnings;
    10 
    11 use IO::String;
    12 use XML::Writer;
    13 
    14 my $xml;
    15 my $output = new IO::String->new($xml);
    16 my $writer = new XML::Writer(	OUTPUT => $output,
    17 								DATA_MODE => 1,
    18 								DATA_INDENT => "	");
    19 
    20 $writer->xmlDecl("UTF-8");
    21 $writer->startTag("fstab");
    22 
    23 my $fstab;
    24 open($fstab, "<", "/etc/fstab");
    25 while (my $r = <$fstab>) {
    26 	if ($r !~ /^\x23/ && $r =~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/) {
    27 		$writer->startTag("bod");
    28 		$writer->dataElement("zařízení", "$1");
    29 		$writer->dataElement("přípojnýBod", "$2");
    30 		$writer->dataElement("souborovýSystém", "$3");
    31 
    32 		$writer->startTag("volby");
    33 		my @volby = split(",", $4);
    34 		foreach my $volba (@volby) {
    35 			$writer->dataElement("volba", "$volba");
    36 		}
    37 		$writer->endTag();
    38 
    39 		$writer->dataElement("dump", "$5");
    40 		$writer->dataElement("pass", "$6");
    41 		$writer->endTag();
    42 	}
    43 }
    44 
    45 $writer->endTag();
    46 print $xml;
    47 print "\n";
    48