Kwaker
Kwaker

Reputation: 45

How to mount not presented in fstab

I have a script which produces information regarding missing volumes, but I can't make use output to mount them back. Could you please help me?

#!/bin/bash
mountpoints=( $(awk '$1 !~ /^#/ && $2 ~ /^[/]/ {print $2}' /etc/fstab) )
for mount in ${mountpoints[@]}; do
   if ! findmnt "$mount" &> /dev/null; then
      echo "$mount is declared in fstab but not mounted"
   fi
done

Upvotes: 0

Views: 329

Answers (1)

Lohit Gupta
Lohit Gupta

Reputation: 1081

Try putting the findmnt command in parameter execution scope -

#!/bin/bash
mountpoints=( $(awk '$1 !~ /^#/ && $2 ~ /^[/]/ {print $2}' /etc/fstab) )
for mount in ${mountpoints[@]}; do
if ! $(findmnt "$mount") &> /dev/null; then
  echo "$mount is declared in fstab but not mounted"
fi
done

Upvotes: 1

Related Questions