* getmntent wrapper?
@ 2016-09-26 22:25 Andreas Fenkart
2016-09-26 22:36 ` Dave Reisner
0 siblings, 1 reply; 2+ messages in thread
From: Andreas Fenkart @ 2016-09-26 22:25 UTC (permalink / raw)
To: util-linux
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?
Andi
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: getmntent wrapper?
2016-09-26 22:25 getmntent wrapper? Andreas Fenkart
@ 2016-09-26 22:36 ` Dave Reisner
0 siblings, 0 replies; 2+ messages in thread
From: Dave Reisner @ 2016-09-26 22:36 UTC (permalink / raw)
To: Andreas Fenkart; +Cc: util-linux
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-26 22:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-26 22:25 getmntent wrapper? Andreas Fenkart
2016-09-26 22:36 ` Dave Reisner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox