#!/usr/bin/perl -w use JSON; opendir(my $dh, "/sys/block") or die "Couldn't open /sys/block: $!"; my @blocks = grep { $_ !~ m/^\./ } readdir($dh); closedir($dh); my $json; foreach my $block (@blocks){ my $removable = 0; my $size = 1; if ( -e "/sys/block/$block/removable"){ open REMOVABLE, "/sys/block/$block/removable"; $removable = join "", ; close REMOVABLE; chomp($removable); next if ($removable eq '1'); } if ( -e "/sys/block/$block/size"){ open SIZE, "/sys/block/$block/size"; $size = join "", ; close SIZE; chomp($size); next if ($size eq '0'); } push @{$json->{data}}, { "{#BLOCKDEVICE}" => $block, "{#BLOCKSIZE}" => $size }; } print to_json($json); exit(0);