Util-Linux package development
 help / color / mirror / Atom feed
From: Dave Reisner <d@falconindy.com>
To: Andreas Fenkart <afenkart@gmail.com>
Cc: util-linux@vger.kernel.org
Subject: Re: getmntent wrapper?
Date: Mon, 26 Sep 2016 18:36:45 -0400	[thread overview]
Message-ID: <20160926223645.GB13829@rampage> (raw)
In-Reply-To: <CALtMJED52KKWgMmg+hcGavZAP6fwh_AbTWFZKz+LYEWszsjLJw@mail.gmail.com>

On Tue, Sep 27, 2016 at 12:25:32AM +0200, Andreas Fenkart wrote:
> Hi,
> 
> Parsing /etc/fstab or /proc/mount with sed/awk is awful and platform
> dependent. Would it be acceptable to add a wrapper for getmntent to
> parse those files and make the content available to shell scripts?
> 
> Typical use is to check if a given device is already mounted and
> returning its mountpoint. In case a device is mounted twice or more,
> several mountpoints will be listed
> 
> $ getmntent -f /proc/mounts /dev/sda4
> /mnt/
> /home/user/bind
> 
> Playing around with mount parsing the output with awk seems to work
> pretty well. It avoids to handle the whitespace separately.
> 
> $ mount -l  | awk  '/\/dev\/sda4/ { print $3; }'
> 
> negative:
> - I can't use the a different filesystem description file (small minus)
> - Is the output from 'mount' stable?
> 
> Is it worth to add a utility wrapper for getmntent to util-linux?

This sort of functionality already exists in findmnt(1).

$ findmnt -rno TARGET /dev/sdc1
/mnt/Haven
/srv/nfs/pkgs
/srv/nfs/vmbin

      reply	other threads:[~2016-09-26 22:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-26 22:25 getmntent wrapper? Andreas Fenkart
2016-09-26 22:36 ` Dave Reisner [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160926223645.GB13829@rampage \
    --to=d@falconindy.com \
    --cc=afenkart@gmail.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox