perl/perl-fstab.pl
author František Kučera <franta-hg@frantovo.cz>
Tue Nov 21 00:20:27 2017 +0100 (2017-11-21)
changeset 54 2a22f9959ea3
permissions -rwxr-xr-x
přepis-cli-parametrů: první verze
     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