I am trying to write a script that runs on boot that checks to see if the boot filesystem is read only, if it is, then run fsck to fix permissions and reboot. Point 1: I am having trouble figuring out how to grep just the permissions line from a ls command. Point 2: I am also having trouble figuring out how to check if that command returns a string without w in it. For example, an ls -l command returns a line similar to the following: drwx-----+    5 Admin  staff   170 Oct 12 05:41 DocumentsI want to grab just the following string: drwx-----+Then, check if it does not contain write permissions.Below is the script I have so far.#!/bin/bash$DIR='home'#If $DIR has only read permissions run loopif [[ #point 1 = #point 2 ]] then    #fix permissions on $DIR    umount ${DIR}    fsck    rebootfi
How do I grep a directories permissions and see if it lacks write permissions?
files;permissions
Do not ever parse the output of ls. Scripting 101.man findman findmntThe root file system is never mounted read-only if the system has reached the multiuser target or runlevel. This means that the only user who can ever find the root file system mounted read-only is root. And root can write everywhere regardless of permissions. Therefore, to check whether the root filesystem is readonly you can simply try to touch a file:if touch /testfile ; then# The root filesystem is read-write  rm /testfileelse# The root filesystem is read-only# Do something about itfiHowever, this should not be needed. The system should drop into a single-user shell if it cannot mount the root file system read-write.