I took the sample script, below, off the net to check and validate mount points of system that is already up and running.

The problem: I want to compare existing mounted-mount points which are not commented out in the /etc/fstab and highlighting them if they are on.

Also, I would like to inquire if there is any alternative solution!

while read ip;
    echo "connecting to $ip";
    ssh root@$ip "until mount | grep -w \"/mnt/data\" >/dev/null;
     do echo mounting \"/mnt/data\"; mount \"/mnt/data\"; sleep 1; done && 
     echo Mounted on $ip"
done < ips.txt
  • That script looks for one mount point (/mnt/data) on a bunch of servers. That's not what you want.
    – RonJohn
    Commented Sep 13, 2018 at 15:23
  • Do you want: the list of currently-mounted filesystems that are not "active" in /etc/fstab, or do you want: the list of "active" entries in /etc/fstab that are not mounted?
    – Jeff Schaller
    Commented Sep 13, 2018 at 16:31
  • Linking in: unix.stackexchange.com/q/395721/117549
    – Jeff Schaller
    Commented Sep 13, 2018 at 16:34

2 Answers 2


This appears to do the trick:

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"

Stealing borrowing DopeGhoti's awk, you could use comm for this:

Filesystems that are mounted but not in /etc/fstab:

comm -23 <(mount|awk '{print $3}'|sort) <(awk '$1 !~ /^#/ && $2 ~ /^[/]/ {print $2}' /etc/fstab|sort)

Filesystems that are in /etc/fstab but not mounted:

comm -13 <(mount|awk '{print $3}'|sort) <(awk '$1 !~ /^#/ && $2 ~ /^[/]/ {print $2}' /etc/fstab|sort)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .