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=G1wOAWtmkhvq2RsUpMNU0mXepofr8gF7ZutvCnMkhbg=; b=Kv19OU80aKTAUvxiWzXPbgoeOI2p0y3aVb1WnqdKAMFjW1pPGIVpyqRbyIVITu0KZE UaF5b7s9yJBbG+oIfFDWlk1tj8Iq5frYw/2xsvEkvpaxujejyLYLCj5VMoeLRDE08Ck3 q1NUfW4CWT9KBRfM7oNInrjYZKgQHXiu1GPZGMoBMfR6mpQVM7TOScvah4aJtmBDmkH/ GzbxNG0wPE0z3KsQQWv2GszD5bKnHUbjNYpXQpXk1trZhaU1e7ZyHfWG0Rb1N6nXkKuM 5Erk+D47ge9o7Ivv+a9iyIDyI5lpuaVzC0P0e85kmWGH9HcOj6wgu07pcHL/Kgg+EBQ3 75kQ== X-Received: by 10.112.167.67 with SMTP id zm3mr491139lbb.27.1406681567452; Tue, 29 Jul 2014 17:52:47 -0700 (PDT) Sender: Denis Smirnov Date: Wed, 30 Jul 2014 04:52:44 +0400 From: =?koi8-r?B?5MXOydMg883J0s7P1w==?= To: community@lists.altlinux.org Message-ID: <20140730005244.GB32238@mw.mithraen.ru> Mail-Followup-To: community@lists.altlinux.org References: <53D1614C.9080402@rambler.ru> <1082471406231394@web30h.yandex.ru> <20140725012132.5a6a5835@sem-notebook> <1256811406243387@web28h.yandex.ru> <20140728234111.GB19913@mw.mithraen.ru> <3406861406630905@web13j.yandex.ru> <20140729161619.GB7385@mw.mithraen.ru> <719891406657587@web4h.yandex.ru> <20140729192028.GA2059@mw.mithraen.ru> <845131406663561@web16j.yandex.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ZwgA9U+XZDXt4+m+" Content-Disposition: inline In-Reply-To: <845131406663561@web16j.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: Wed, 30 Jul 2014 00:52:55 -0000 Archived-At: List-Archive: List-Post: --ZwgA9U+XZDXt4+m+ Content-Type: multipart/mixed; boundary="BwCQnh7xodEAoBMC" Content-Disposition: inline --BwCQnh7xodEAoBMC Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jul 29, 2014 at 11:52:41PM +0400, Speccyfighter wrote: >> find /dev/disk/by-id/ -name usb-* -print0 \ >> =9A=9A=9A=9A| xargs -0 realpath \ >> =9A=9A=9A=9A| sort \ >> =9A=9A=9A=9A| xargs lsblk -d -l -o NAME,MOUNTPOINT,LABEL,FSTYPE,SIZE > =F7=CF-=D7=CF-=D7=CF! =F4=CF =DE=D4=CF =CE=C1=C4=CF. =EB=CF=D2=CF=D4=CB= =CF =C9 =D7=D3=A3 =CE=C5=CF=C2=C8=CF=C4=C9=CD=CF=C5 =C4=CC=D1 plmount > =CE=C1 =CD=C5=D3=D4=C5: > =EF=C4=CE=CF =D3=CF=CD=CE=C5=CE=C9=C5 =C2=C5=D2=A3=D4: =C5=D3=D4=D8 =CC= =C9 =CE=C5=CF=C2=C8=CF=C4=C9=CD=CF=D3=D4=D8 =D7 SIZE? =F7 =D3=CC=D5=DE=C1=C5 =CE=C5=D3=CB=CF=CC=D8=CB=C9=C8 =C4=C5=D7=C1=CA=D3=CF= =D7 SIZE =CF=C4=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F =CC=C9 =DC=D4=CF -- =CE=C5 =D5=D7=C5=D2= =C5=CE. =E5=D3=CC=C9 =CE=C5 =CE=D5=D6=CE=CF, =CD=CF=D6=CE=CF =CC=C5=C7=CB= =CF =CF=C2=CF=CA=D4=C9=D3=D8 shell'=CF=CD =C2=C5=DA =D7=D3=D1=CB=C9=C8 =C9=DA=D7=D2=C1=DD=C5=CE=C9=CA = =D3 =D0=C5=D2=CC=CF=D7=CB=CF=CA. P.S. =E5=D3=CC=C9 =C2=D5=C4=C5=D4 =D2=D5=C7=C1=D4=D8=D3=D1 =CE=C1 Text::Tab= le -- apt-get install perl-Text-Table --=20 =F3 =D5=D7=C1=D6=C5=CE=C9=C5=CD, =E4=C5=CE=C9=D3 http://mithraen.ru/ --BwCQnh7xodEAoBMC Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=lmount #!/usr/bin/perl -w #============================================================================# # List all block devices that not exists in fstab # #============================================================================# # (C) Denis Smirnov # #============================================================================# use strict; use warnings qw(FATAL all); use utf8; use open qw(:utf8 :std); 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 RO,KNAME` ); foreach (@devs) { next unless /^1\s+(.+)$/; $devices{$1} = 1; } } # Parse /etc/fstab my %disks; my %fstab_dev; my %fstab_uuid; my %fstab_label; sub parse_fstab() { open( my $fh, "<", "/etc/fstab" ) || die; while (<$fh>) { s/#.*//; next if /^\s*$/; s/\s+.*$//; s/\s+$//; if (/^LABEL=\"([^\"]+)\"/) { $fstab_label{$1} = 1; } elsif (/^LABEL=([^\"]+)/) { $fstab_label{$1} = 1; } if (/^UUID=\"([^\"]+)\"/) { $fstab_uuid{$1} = 1; } elsif (/^UUID=([^\"]+)/) { $fstab_uuid{$1} = 1; } else { my $dev = $_; $dev = abs_path($dev) if -l $dev; $fstab_dev{$dev} = 1; } } close($fh); } 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' ) { use Data::Dump qw/ddx/; $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; } parse_fstab; 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; --BwCQnh7xodEAoBMC-- --ZwgA9U+XZDXt4+m+ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlPYQdoACgkQPuR8c4jhFKICkwCglwmw8gysMs84ep/zO9+4kz4t XhEAn1xtMXfxNUmiXS3f8gURtCTu1k5D =ZmnM -----END PGP SIGNATURE----- --ZwgA9U+XZDXt4+m+--