Comparing mounted-mount points with fstab

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












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









share|improve this question























  • That script looks for one mount point (/mnt/data) on a bunch of servers. That's not what you want.
    – RonJohn
    Sep 13 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 at 16:31










  • Linking in: unix.stackexchange.com/q/395721/117549
    – Jeff Schaller
    Sep 13 at 16:34














up vote
0
down vote

favorite












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









share|improve this question























  • That script looks for one mount point (/mnt/data) on a bunch of servers. That's not what you want.
    – RonJohn
    Sep 13 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 at 16:31










  • Linking in: unix.stackexchange.com/q/395721/117549
    – Jeff Schaller
    Sep 13 at 16:34












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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









share|improve this question















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






bash scripting mount






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 13 at 16:00









Goro

5,47052460




5,47052460










asked Sep 13 at 15:18









JackyBoi

11517




11517











  • That script looks for one mount point (/mnt/data) on a bunch of servers. That's not what you want.
    – RonJohn
    Sep 13 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 at 16:31










  • Linking in: unix.stackexchange.com/q/395721/117549
    – Jeff Schaller
    Sep 13 at 16:34
















  • That script looks for one mount point (/mnt/data) on a bunch of servers. That's not what you want.
    – RonJohn
    Sep 13 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 at 16:31










  • Linking in: unix.stackexchange.com/q/395721/117549
    – Jeff Schaller
    Sep 13 at 16:34















That script looks for one mount point (/mnt/data) on a bunch of servers. That's not what you want.
– RonJohn
Sep 13 at 15:23




That script looks for one mount point (/mnt/data) on a bunch of servers. That's not what you want.
– RonJohn
Sep 13 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 at 16:31




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 at 16:31












Linking in: unix.stackexchange.com/q/395721/117549
– Jeff Schaller
Sep 13 at 16:34




Linking in: unix.stackexchange.com/q/395721/117549
– Jeff Schaller
Sep 13 at 16:34










2 Answers
2






active

oldest

votes

















up vote
0
down vote













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





share|improve this answer



























    up vote
    0
    down vote













    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)





    share|improve this answer




















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468824%2fcomparing-mounted-mount-points-with-fstab%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      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





      share|improve this answer
























        up vote
        0
        down vote













        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





        share|improve this answer






















          up vote
          0
          down vote










          up vote
          0
          down vote









          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





          share|improve this answer












          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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 13 at 15:50









          DopeGhoti

          41.3k55180




          41.3k55180






















              up vote
              0
              down vote













              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)





              share|improve this answer
























                up vote
                0
                down vote













                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)





                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  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)





                  share|improve this answer












                  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)






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 13 at 16:41









                  Jeff Schaller

                  33.1k849111




                  33.1k849111



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468824%2fcomparing-mounted-mount-points-with-fstab%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Christian Cage

                      How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?