added with-partitions so we can quickly list devices for fdisk
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 1 May 2009 12:11:44 +0000 (12:11 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 1 May 2009 12:11:44 +0000 (12:11 +0000)
git-svn-id: svn://svn.rot13.org/sysadmin-cookbook@13 191e9f34-6774-4a6d-acfc-7664dacd4a2a

bin/block-devices

index 99cfdd5..0543c93 100755 (executable)
@@ -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;
        }
 }