0

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!

#!/bin/bash
while read ip;
do
    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
3
  • That script looks for one mount point (/mnt/data) on a bunch of servers. That's not what you want. – RonJohn Sep 13 '18 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 Sep 13 '18 at 16:31
  • Linking in: unix.stackexchange.com/q/395721/117549 – Jeff Schaller Sep 13 '18 at 16:34
1

This appears to do the trick:

#!/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
0

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.