From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.2.5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-type:content-disposition:in-reply-to; bh=wrY54O8gunpOpoLd4IwK71a0rg3GZoIu7G988bLDvFQ=; b=jWmJLphR4tiZJF3UZ39fVYstDUwnziecBAuYeI4DMI3p7BtjxEjkckVuYCd2JRu6q0 cnFgqrVYoLfuAqRRMoq7y5kzf9yXhdCLKAOLWkgisjqK0V/wba2o5f43JoG03S3SICcf FK8I4f61zjaPlp9YcgHzjIz9xOe4tnzwd6TLHsw9gipMpDYaLE+0WuBTbIMJpZHyP2vT FdWdJjx8pREKhlXGWUijmdcHikzbz/x7TA+NrYdXXc8OeAH04qLI2okSRDelrYIT/fc8 lG2rtn0bXwHBUpHc1Pye4zzB6KWVmnHFzKDhElm9Tsew9rd/P7HnufLVxvT6N5Idn1Wa oSsw== X-Received: by 10.112.166.2 with SMTP id zc2mr195162lbb.98.1406833538287; Thu, 31 Jul 2014 12:05:38 -0700 (PDT) Sender: Denis Smirnov Date: Thu, 31 Jul 2014 23:05:34 +0400 From: =?koi8-r?B?5MXOydMg883J0s7P1w==?= To: community@lists.altlinux.org Message-ID: <20140731190534.GA20662@mw.mithraen.ru> Mail-Followup-To: community@lists.altlinux.org References: <20140729192028.GA2059@mw.mithraen.ru> <845131406663561@web16j.yandex.ru> <20140730005244.GB32238@mw.mithraen.ru> <1208071406690813@web8g.yandex.ru> <20140730181141.GA11396@mw.mithraen.ru> <292221406772030@web23h.yandex.ru> <20140731140622.GA8662@mw.mithraen.ru> <143291406817580@web22h.yandex.ru> <20140731164759.GA12540@mw.mithraen.ru> <560801406828159@web24j.yandex.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="WYTEVAkct0FjGQmd" Content-Disposition: inline In-Reply-To: <560801406828159@web24j.yandex.ru> Subject: Re: [Comm] =?koi8-r?b?wdfUz83PztTJ0s/Xwc7JxSDCxdogREU=?= X-BeenThere: community@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Community general discussions List-Id: ALT Linux Community general discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jul 2014 19:05:46 -0000 Archived-At: List-Archive: List-Post: --WYTEVAkct0FjGQmd Content-Type: multipart/mixed; boundary="BXVAT5kNtrzKuDFl" Content-Disposition: inline --BXVAT5kNtrzKuDFl Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jul 31, 2014 at 09:35:59PM +0400, Speccyfighter wrote: >> $ /bin/lsblk -d -r -o RO,KNAME > =F7=D9=C4=C1=CC=C1: > $ /bin/lsblk -d -r -o RO,KNAME > RO KNAME > 0 sda > 0 sdb > 0 sdc > 0 sr0 =EF, =D5 =CD=C5=CE=D1 =C2=D9=CC=C1 =CF=DE=C5=D0=D1=D4=CB=C1 =D7 =D3=CB=D2= =C9=D0=D4=C5. =EE=C1=C4=CF =C2=D9=CC=CF RM =C1 =CE=C5 RO. Fixed, =D7 =C1=D4= =D4=C1=DE=C5. --=20 =F3 =D5=D7=C1=D6=C5=CE=C9=C5=CD, =E4=C5=CE=C9=D3 http://mithraen.ru/ --BXVAT5kNtrzKuDFl Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=lmount #!/usr/bin/perl #============================================================================# # List all block devices that not exists in fstab # #============================================================================# # (C) Denis Smirnov # #============================================================================# use strict; use warnings qw(FATAL all); use Cwd 'abs_path'; use Text::Table; my %devices; # List all USB devices foreach ( glob("/dev/disk/by-id/usb-*") ) { $devices{ abs_path($_) } = 1; } # List all removable devices { my @devs = split( "\n", `/bin/lsblk -d -r -o RM,KNAME` ); foreach (@devs) { next unless /^1\s+(.+)$/; $devices{$1} = 1; } } # List all devices in /etc/pmount.allow if ( open my $fh, "<", "/etc/pmount.allow" ) { while (<$fh>) { s/#.*//; s/\s+$//; next if $_ eq ''; $_ = abs_path($_) if -l $_; $devices{$_} = 1; } close $fh; } # Parse /etc/fstab my %disks; my %fstab_dev; my %fstab_uuid; my %fstab_label; sub parse_fstab($) { open( my $fh, "<", $_[0] ) || return; my @out; while (<$fh>) { my %h; s/#.*//; s/\s+$//; next if $_ eq ''; my ( $dev, $uuid, $label ) = ( '', '', '' ); if (s/^UUID=([^\s"]+)\s+//) { $uuid = $1; $h{uuid} = $1; } elsif (s/^UUID="([^"]+)"\s+//) { $uuid = $1; $h{uuid} = $1; } elsif (s/^LABEL=([^\s"]+)\s+//) { $label = $1; $h{label} = $1; } elsif (s/^LABEL="((?:[^"]|"")+)"\s+//) { $label = $1; $label =~ s/""/"/g; $h{label} = $1; } elsif (s/^([^\s"]+)\s+//) { $dev = $1; $h{dev} = $1; } else { next; } my @fields = split( /\s+/, $_ ); $h{mountpoint} = shift(@fields); $h{fs} = shift(@fields); my @opts = split( ',', shift(@fields) ); foreach my $opt (@opts) { $h{opts}->{$opt} = 1; } push @out, \%h; } close $fh; return @out; } sub parse_line($) { my $fields = $_[0]; my %h; while ( $fields =~ s/^\s*([^"]+)="([^\"]*)"\s*// ) { $h{$1} = $2; } my $dev = $h{KNAME}; if ( $h{TYPE} eq 'disk' ) { $disks{$dev} = \%h; } if ( $h{TYPE} eq 'part' ) { my $basedev = $dev; $basedev =~ s/\d+$//; foreach my $key ( keys %h ) { if ( $h{$key} eq '' ) { $h{$key} = $disks{$basedev}->{$key}; } } } return if $h{FSTYPE} eq ''; return if $h{FSTYPE} eq 'swap'; return if $h{FSTYPE} eq 'linux_raid_member'; return if $h{FSTYPE} eq 'LVM2_member'; # skip LVM partitions # return if $h{TYPE} eq 'lvm'; # skip FS in fstab return if defined $fstab_label{ $h{LABEL} }; return if defined $fstab_uuid{ $h{UUID} }; return if defined $fstab_dev{ "/dev/" . $h{KNAME} }; return \%h; } foreach ( parse_fstab "/etc/fstab" ) { if ( defined $_->{opts}->{user} ) { if ( defined $_->{dev} ) { my $dev = $_->{dev}; $dev = abs_path($dev) if -l $dev; $devices{$dev} = 1; } next; } if ( defined $_->{dev} ) { my $dev = $_->{dev}; $dev = abs_path($dev) if -l $dev; $fstab_dev{$dev} = 1; } $fstab_label{ $_->{label} } = 1 if defined $_->{label}; $fstab_uuid{ $_->{uuid} } = 1 if defined $_->{uuid}; } my @out; # Get all info about removable and USB devices open( my $fh, "-|", '/bin/lsblk', '-o', 'NAME,FSTYPE,LABEL,MOUNTPOINT,SIZE,RM,KNAME,MODEL,TYPE,UUID', '-P' ); my $tb = Text::Table->new( 'NAME', 'MOUNTPOINT', 'LABEL', 'FSTYPE', "SIZE\n&left", 'MODEL' ); while (<$fh>) { my $h = parse_line($_); next unless defined $h; next unless defined $devices{ "/dev/" . $h->{KNAME} }; $tb->add( $h->{NAME}, $h->{MOUNTPOINT}, $h->{LABEL}, $h->{FSTYPE}, $h->{SIZE}, $h->{MODEL} ); my $dev = "/dev/" . $h->{KNAME}; push @out, $dev; } print $tb; --BXVAT5kNtrzKuDFl-- --WYTEVAkct0FjGQmd Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlPak30ACgkQPuR8c4jhFKLPWACfYE2RBj57eE4v6TU/4q1g9vrm m24AniumgW2fAkJtsHRVZoMJLO9VVbXC =oprH -----END PGP SIGNATURE----- --WYTEVAkct0FjGQmd--