From: Dobrica Pavlinusic Date: Fri, 1 May 2009 12:11:44 +0000 (+0000) Subject: added with-partitions so we can quickly list devices for fdisk X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=319368e89419cb58f9c3d862221ecfa3a133bc07;p=sysadmin-cookbook added with-partitions so we can quickly list devices for fdisk git-svn-id: svn://svn.rot13.org/sysadmin-cookbook@13 191e9f34-6774-4a6d-acfc-7664dacd4a2a --- diff --git a/bin/block-devices b/bin/block-devices index 99cfdd5..0543c93 100755 --- a/bin/block-devices +++ b/bin/block-devices @@ -6,16 +6,20 @@ Display all block devices on system hdparm -t `block-devices` + sfdisk -l `block-devices with-partitions` + =cut use warnings; use strict; #use autodie; +my $with_partitions = { true => 1 } if grep { m/with.?partitions/ } @ARGV; + open(my $proc, '<', '/proc/partitions'); my @header; -my $last_device; +my $last_device = ''; my $name2col; sub col { @@ -37,10 +41,16 @@ while(<$proc>) { next unless $_; my $device = col 'name', $_; - if ( $last_device && substr( $device, 0, length($last_device) ) eq $last_device ) { - warn "# partition $device\n"; + my $device_like_last = substr( $device, 0, length($last_device) ); + if ( $last_device && $device_like_last eq $last_device ) { + if ( $with_partitions ) { + print "/dev/$device_like_last\n" if ! $with_partitions->{ $device_like_last }++; + } else { + warn "# partition $device\n"; + } } else { - print '/dev/', $last_device = $device, $/; + print "/dev/$device\n" unless $with_partitions; + $last_device = $device; } }