Script to unmount and mount by UUID

Hi,

Need a bit of help on this one as I am a scripting noob.

I have a linux based NAS that mounts USB hard drives in an inconsistent location and to make matters worse, seems to lose the mount for an unknown reason and doesn't remount automatically unless the drive is removed and re-inserted.

I'd like to make a script with that checks for a mounted drive by UUID, then checks it's mounted location and if not mounted in the location I want, unmounts then remounts in the correct location

What I have been able to figure out so far is that I can use

usbuuid=917086e7-9115-44fe-b176-b1a79f04e739
blkid|grep $usbuuid

to find it's /dev/xxx location, but I still need to parse the results to get rid of the extra info, and I'd like to then put the parsed info into a variable say usbdev.

I want to then used that variable with

mount|grep $usbdev

Again I need to parse the result to find the mount location, if any

If mounted, but not mounted in my desired location, I want to unmount it and remount it in the correct location. If not mounted, mount. If mounted correctly, do nothing. Then keep checking routinely in case the mount is lost.

I should point out that I can't change fstab. It's protected and even if I change it reverts on reboot.

I can schedule a cron job, or a startup script.

The other would be to dynamically create or change a dynamic link to which ever location the system mounts the USB, but I would still need a script to check if it's mounted and re-mount if necessary, and I have a problem that samble does not follow symbolic links and this setting can't be changed.

Any help would be appreciated.

Mark

Can you check and/or modify the udev rules on your NAS? Do you have access to udevadm ? Perhaps you could check that out ( udevadm monitor )...

No udevadml using the shell, and I couldn't find it using 'find'. Can't edit isn't rules either. They get overwritten immediately.

That should be something like /sbin/udevadm What is the Linux Distribution and version?

I'll have to look around for the exact distro.

This is the sbin folder and uname -a

root@127.0.0.1:~# cd /sbin
root@127.0.0.1:/sbin# ls
acpi_listen*       ext2prepare*       hwclock@           klogd@             lvdisplay@         lvrename@          mkreiserfs*        poweroff@          reboot@            start-stop-daemon@ udhcpc@            vgexport@          vgscan@
acpid*             ext2resize*        ifconfig@          ldconfig*          lvextend@          lvresize@          mkswap@            pvchange@          reiserfsck*        strace*            vconfig@           vgextend@          vgsplit@
adjtimex@          fdisk*             ifenslave*         loadkmap@          lvm*               lvs@               modprobe@          pvcreate@          resize2fs*         sulogin@           vgcfgbackup@       vgimport@          watchdog@
agetty*            freeramdisk@       ifrename*          logread@           lvmchange@         lvscan@            nameif@            pvdisplay@         resize_reiserfs*   swapoff@           vgcfgrestore@      vgmerge@           zcip@
depmod*            fsck.minix@        init@              losetup*           lvmdiskscan@       makedevs@          pidof@             pvmove@            rmmod@             swapon@            vgchange@          vgmknodes@
devfsd@            getty@             insmod@            lsmod@             lvmsadc@           mdadm*             pivot_root@        pvremove@          route@             switch_root@       vgck@              vgreduce@
dumpe2fs*          halt@              iwconfig*          lvchange@          lvmsar@            mdev@              pmap_dump*         pvresize@          runlevel@          sysctl@            vgconvert@         vgremove@
e2fsck*            hdparm*            iwpriv*            lvconvert@         lvreduce@          mke2fs*            pmap_set*          pvs@               setconsole@        syslogd@           vgcreate@          vgrename@
ext2online*        hotplug*           killall5*          lvcreate@          lvremove@          mkfs.minix@        portmap*           pvscan@            sgdisk*            tune2fs*           vgdisplay@         vgs@
root@127.0.0.1:/sbin# uname -a
Linux NAS 2.6.33N7700 #5 SMP Tue May 3 17:37:03 CST 2011 i686 unknown
root@127.0.0.1:/sbin#

---------- Post updated at 09:20 AM ---------- Previous update was at 09:06 AM ----------

All i can find is that its their own version of Linux with busybox.