Looking for a way to check mount point is mounted and is writable

Discussion in 'General Linux' started by matthes138, Nov 15, 2011.

  1. matthes138

    matthes138 New Member

    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Looking for a way to check a mount point is mounted and is writable and if not remount the mount point. For some reason this mount point will become unavailable to write too and when the script runs, to copy files to the mount point it fails.
    In the fstab it is listed as
    /dev/sdc1 /mnt/iscsi ext3 _netdev 0 0
    this has worked fine for a couple of years but now it will get lost for some reason?
    And if I umount and mount the device again it will work for a while?

    I need to write a shell script to monitor a Linux mount point on Linux. Basically, this is what I want the script to do:

    * check if the mount point is there; if yes, do nothing

    * if no, try to mount it again
    I can put this into a cron job to run ever so often



    Thanks for any help.

  2. Rob

    Rob Administrator Staff Member

    Messages:
    573
    Likes Received:
    185
    Trophy Points:
    43
    Hi matthes - welcome to Linux Forum!

    You could throw something like this into /usr/local/bin/check-mount.sh:
    Code:
    #!/bin/sh
    if grep -qs '/dev/sdc1' /proc/mounts; then
            echo "drive is mounted." >> /var/log/mounted.log
    else
            mount /dev/sdc1
            echo "I mounted your drive." >> /var/log/mounted.log
    fi
    
    Then call it nightly in cron ..

    You could do other things like add the date to it, etc.. but this will check, then output to the log if it needed to remount it.

    This is also assuming that you have this drive set up in /etc/fstab :)

    Rob
  3. matthes138

    matthes138 New Member

    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    thank you Rob
  4. Rob

    Rob Administrator Staff Member

    Messages:
    573
    Likes Received:
    185
    Trophy Points:
    43
    no problem.. i just fixed a typo i had in there (said sdc in one case then sdc1 in the other).. should work now..
  5. matthes138

    matthes138 New Member

    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    is there a way to check of the drive has become un-writable ?
  6. matthes138

    matthes138 New Member

    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Is there a way to check the difference of the output
    like here when you do the grep '/dev/sdc1' /proc/mounts
    good output
    /dev/sdc1 /mnt/iscsi ext3 rw,data=ordered 0 0
    bad ouput
    /dev/sdc1 /mnt/iscsi ext3 ro,data=ordered 0 0
    this is when i want to then re mount the drive then?
    both show it is mounted when using the above script?
  7. matthes138

    matthes138 New Member

    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    rob, Is there a way to check the difference of the output
    like here when you do the grep '/dev/sdc1' /proc/mounts
    good output
    /dev/sdc1 /mnt/iscsi ext3 rw,data=ordered 0 0
    bad ouput
    /dev/sdc1 /mnt/iscsi ext3 ro,data=ordered 0 0
    this is when i want to then re mount the drive then?
    both show it is mounted when using the above script?

Share This Page