/[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

Annotation of /bin/block-devices

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (hide annotations)
Fri May 1 12:00:18 2009 UTC (13 years, 7 months ago) by dpavlin
File size: 822 byte(s)
Display all block devices on system

1 dpavlin 12 #!/usr/bin/perl
2    
3     =head1 block-devices
4    
5     Display all block devices on system
6    
7     hdparm -t `block-devices`
8    
9     =cut
10    
11     use warnings;
12     use strict;
13     #use autodie;
14    
15     open(my $proc, '<', '/proc/partitions');
16    
17     my @header;
18     my $last_device;
19    
20     my $name2col;
21     sub col {
22     my ( $name, $line ) = @_;
23     if ( ! $name2col ) {
24     $name2col->{ $header[$_] } = $_ foreach 0 .. $#header;
25     }
26     $line =~ s/^\s+// || die "expected line to start with space: $_\n";
27     my @c = split(/\s+/, $line, $#header + 1 );
28     return $c[ $name2col->{ $name } ];
29     }
30    
31     while(<$proc>) {
32     chomp;
33     if ( ! @header ) {
34     @header = split(/\s+/, $_);
35     next;
36     }
37     next unless $_;
38    
39     my $device = col 'name', $_;
40     if ( $last_device && substr( $device, 0, length($last_device) ) eq $last_device ) {
41     warn "# partition $device\n";
42     } else {
43     print '/dev/', $last_device = $device, $/;
44     }
45     }
46    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26