Using awk to add mount options in /etc/fstab

Here is a simple example of using awk to add mount options to /etc/fstab entries. In this example we are adding the ‘nofail’ option to all entries starting with UUID that don’t already have the option

# awk '/^UUID/ { if(!match(/nofail/, $4)) $4=$4",nofail" } 1' /etc/fstab > /tmp/fstab.new
# cp /tmp/fstab.new /etc/fstab
# chmod 644 /etc/fstab
# rm /tmp/fstab.new

You may also like...