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