I need to verify if a particular file system has the noexec option set.
For example /dev/shm
. I am running the command in the following manner:
get_val=$(mount|grep /dev/shm )
if [[ -z get_val ]] ; then
# Error
else
value=$(echo "${get_val}" | cut -d " " -f 6 | grep noexec)
if [ "${value}" = "" ]; then
# Not set
else
# Set
fi
fi
The value of get_val is something like devshm on /dev/shm type devshm (rw,noexec,nosuid,gid=5,mode=0620)
Next what I want to do is check if gid
and mode
has been set to a certain value. However, with the above procedure, I can only check if an option is set.
So I tried this:
echo "${get_val}"| cut -d " " -f 6 | awk -F, '{
if ($4 == "gid=123"){
print 1;
}
else
{ print 0;}
if ($5 == "mode=123)"){
print 1;
}
else
{ print 0;}'
However, this seems too hassle-ish and I am not sure what will be the better way to do this.
Also other parameters could be set in a filesystem such as nodev etc which would make $5 or $2 different.
any suggestions?