Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: Is there a way to make a directory not appear if nothing is mounted to it?

  1. #11
    Join Date
    Sep 2007
    Location
    Oklahoma, USA
    Beans
    2,378
    Distro
    Xubuntu 16.04 Xenial Xerus

    Re: Is there a way to make a directory not appear if nothing is mounted to it?

    Elegant solution, Cheesemill!!!

    To explain for the benefit of others who may come across this thread later, here's why it works: If the device is actually mounted to the mount point, the empty file "mounted" is hidden from the system and the "if" test will report that the file doesn't exist. However, if the device is not mounted, then the file will show up to the test action. It's not at all obvious at first glance, and unless you understand that mounting the device hides the original content of the directory looks like nonsense.

    I wish I had thought of it!

    EDIT: Actually the directory I was suggesting to test for was located only on the external drive, not in the mount point itself, as suggested much earlier in the thread. However your solution is much cleaner...
    Last edited by JKyleOKC; December 11th, 2012 at 03:12 PM. Reason: To clarify a confusing point.
    --
    Jim Kyle in Oklahoma, USA
    Linux Counter #259718
    Howto mark thread: https://wiki.ubuntu.com/UnansweredPo.../SolvedThreads

  2. #12
    Join Date
    Jul 2006
    Beans
    4,860

    Re: Is there a way to make a directory not appear if nothing is mounted to it?

    I ended up whipping up this script, which is actually braindead easy once you include the mount-detection portion of it as suggested earlier.

    #!/bin/bash
    if [ $(mount | grep -c /media/storage_II) == 1 ]
    then
    rsync -a --delete /media/storage/ /media/storage_II/
    fi
    There's my script for all who's curious.

    Line 1 simply ensures that storage_II is mounted. 1 is mounted, and == means that it must equal 1 in order to move on. After that, you have the "then" factor which flows into the actual rsync command. -a keeps the permissions, ownership, timestamps, etc, and --delete makes sure that storage_II isn't holding on to files that storage no longer has.

    Overall, this works quite nicely. Very happy with it.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •