Skip to content

Instantly share code, notes, and snippets.

@smonff
Last active July 21, 2021 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smonff/bb7e7bab4433fd70d8679357c3692c13 to your computer and use it in GitHub Desktop.
Save smonff/bb7e7bab4433fd70d8679357c3692c13 to your computer and use it in GitHub Desktop.
/proc/mounts to JSON with perlcore only
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use JSON::PP;
my @only = qw(ext4);
my @mounts = ();
for (`cat /proc/mounts`) {
my ($fsname, $fstype, $fsmodes) = m/\S+ (\S+) (\S+) (\S+)/;
next unless grep { $fstype =~ $_ } @only;
push @mounts, {
'#FSNAME' => $fsname,
'#FSTYPE' => $fstype,
'#FSMODES' => $fsmodes,
};
}
print JSON::PP->new->pretty->canonical->encode({ mounts => \@mounts });
@smonff
Copy link
Author

smonff commented Jul 21, 2021

perl mounts2json.pl

{ "mounts" : [
   {
      "#FSMODES" : "rw,relatime,errors=remount-ro",
      "#FSNAME" : "/",
      "#FSTYPE" : "ext4"
   },
   {
     "#FSMODES" : "rw",
     "#FSNAME" : "/data",
     "#FSTYPE" : "ext4"
   }
]}


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment