Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Currently, I'm using grep '\s/location/\s.*noexec' /proc/mounts.
(Is that a right way of checking this?)

share|improve this question
1  
That's fine as long as you only need to work on newer versions of Linux. –  jordanm Sep 17 '13 at 15:03
    
Check this Q/A –  dawud Sep 17 '13 at 15:11

2 Answers 2

up vote 5 down vote accepted

You should use the mount(8) command, which is available out of the box on all Linux and UNIX systems.

If you run mount without any additional arguments, it will list all the currently mounted partitions on your system, file system type and any mount options, such as noexec, rw, or nosuid.

Eg:

% mount
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
/dev/sda1 on /boot type ext4 (rw,relatime,data=ordered)
/dev/mapper/basement-root on / type ext4 (rw,relatime,data=ordered)
share|improve this answer
    
On Linux, I recommend using /proc/mounts in preference to mount. If /etc/mtab is not updated (e.g. because / is read-only), the output of mount may not be up-to-date. Also, for some options (not noexec), mount gives you filtered output which can be misleading for some combinations of versions of the kernel and mount (e.g. with the atime-related options). –  Gilles Sep 17 '13 at 22:34

Assuming that you're running this on Linux, yes, this is fine. It would be a little more robust to check that noexec is between commas or at the beginning or end of its column.

grep -Eq '^[^ ]+ /location [^ ]+ ([^ ]*,)?noexec[, ]' /proc/mounts

This might be clearer in awk:

awk -v location="/location" '$2 == location {exit(!($4 ~ /(^|,)noexec($|,)/))} END {exit(2)}'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.