/[sysadmin-cookbook]/bin/block-devices
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /bin/block-devices

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12 by dpavlin, Fri May 1 12:00:18 2009 UTC revision 13 by dpavlin, Fri May 1 12:11:44 2009 UTC
# Line 6  Display all block devices on system Line 6  Display all block devices on system
6    
7    hdparm -t `block-devices`    hdparm -t `block-devices`
8    
9      sfdisk -l `block-devices with-partitions`
10    
11  =cut  =cut
12    
13  use warnings;  use warnings;
14  use strict;  use strict;
15  #use autodie;  #use autodie;
16    
17    my $with_partitions = { true => 1 } if grep { m/with.?partitions/ } @ARGV;
18    
19  open(my $proc, '<', '/proc/partitions');  open(my $proc, '<', '/proc/partitions');
20    
21  my @header;  my @header;
22  my $last_device;  my $last_device = '';
23    
24  my $name2col;  my $name2col;
25  sub col {  sub col {
# Line 37  while(<$proc>) { Line 41  while(<$proc>) {
41          next unless $_;          next unless $_;
42    
43          my $device = col 'name', $_;          my $device = col 'name', $_;
44          if ( $last_device && substr( $device, 0, length($last_device) ) eq $last_device ) {          my $device_like_last = substr( $device, 0, length($last_device) );
45                  warn "# partition $device\n";          if ( $last_device && $device_like_last eq $last_device ) {
46                    if ( $with_partitions ) {
47                            print "/dev/$device_like_last\n" if ! $with_partitions->{ $device_like_last }++;
48                    } else {
49                            warn "# partition $device\n";
50                    }
51          } else {          } else {
52                  print '/dev/', $last_device = $device, $/;                  print "/dev/$device\n" unless $with_partitions;
53                    $last_device = $device;
54          }          }
55  }  }
56    

Legend:
Removed from v.12  
changed lines
  Added in v.13

  ViewVC Help
Powered by ViewVC 1.1.26