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

M

matthes138

Guest
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.
 


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
 
no problem.. i just fixed a typo i had in there (said sdc in one case then sdc1 in the other).. should work now..
 
is there a way to check of the drive has become un-writable ?
 
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?
 
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?
 

Members online


Latest posts

Top