Automatically mount/unmount external HD?

Discussion in 'macOS' started by todd2000, Feb 12, 2006.

  1. todd2000 macrumors 68000

    Joined:
    Nov 14, 2005
    Location:
    Danville, VA
    #1
    First, Im sorry for posting that thread about selling my computer, i didn't realize it was against the rules, but I do have another question. I just got an external hard drive, and I was wondering if there was a way to have it automatically mount at a certain time, and unmount at a certain time, so i can run my backups, and have it unmount afterwards, I have tried some commands from the terminal, and applescript, but the HD doesn't spin down using those commands. The only way I can get it to spin down is to drag it to the trash, or unmount it with disk utility. Is there anyway to make a drive mount at a set time, and unmount and spin down at a certain time? I would like it to spin down when not in use to minimize the possiblity of failure down the road.

    Thanks
     
  2. todd2000 thread starter macrumors 68000

    Joined:
    Nov 14, 2005
    Location:
    Danville, VA
  3. FireArse macrumors 6502a

    Joined:
    Oct 29, 2004
    #3
    possibly....

    Can you write code for the shell? You should be able to do it for then. I know u can mount/unmount through it - and see if you can do it with regards to time.

    Would be pretty nice to code actually. You could even write the backup code there too.

    hhmmmmm
     
  4. todd2000 thread starter macrumors 68000

    Joined:
    Nov 14, 2005
    Location:
    Danville, VA
    #4
    I've tried the mount/umount command and it just says device busy, I've tried diskutil from the shell, and it unmounts fine but doesn't spin down. As far as getting it to run at certain times I would just have to add a cron job at the specific times. I just can't find commands to mount/unmount, and spin down the drive. Even if it is apple script, I could make that run automatically as well, I just need to know the commands.
     
  5. jalagl macrumors 6502a

    jalagl

    Joined:
    Jun 5, 2003
    Location:
    Costa Rica
    #5
  6. mrichmon macrumors 6502a

    Joined:
    Jun 17, 2003
    #6
    You don't need to unmount the drive for it to spin down. The option "Put the hard drives to sleep when possible" under the energy settings system preference will spin the drives down for you.

    The default timeout to spin down the drives is 10 minutes of no drive activity. If you want to change this time to some other value, there is a utility called "SpindownHD" in developer tools that allows you to change the idle timeout value.

    The other factor you may be noticing is that spotlight will occassionally access the external drives. This will cause the drives to spin up for 10 minutes since the spotlight access is only brief, but then the drive needs to be idle for 10 minutes before it will spin down. If you don't need spotlight to index your external drives you can disable spotlight for these drives to avoid the drive spining up and down due to spotlight.
     
  7. todd2000 thread starter macrumors 68000

    Joined:
    Nov 14, 2005
    Location:
    Danville, VA
    #7
    I was able to get the drive to mount/unmount by playing with those scripts in that link, however it still refuses to spin down when it un-mounts, the only way it spins down is when I drag it to the trash, or unmount with Graphical disk utility. Another thought, is there a way I can use the terminal to figure out what command the graphical Disk Utility is giving BSD when I unmount a disk? So i could just sue that command.
     
  8. todd2000 thread starter macrumors 68000

    Joined:
    Nov 14, 2005
    Location:
    Danville, VA
    #8
  9. todd2000 thread starter macrumors 68000

    Joined:
    Nov 14, 2005
    Location:
    Danville, VA
    #9
    It's not the most advanced but it works

    I made a shell script to mount/unmount my hard drive, and backup my files. Heres how if your interested

    1. Open terminal and type pico backup.sh
    2.copy and paste the following into the empty file

    diskutil mountDisk `disktool -l |grep Backup | awk '{ print substr($0,20,7) }'`

    cp -rv /Volumes/"Macintosh HD"/Users/Todd /Volumes/Backup/Home
    cp -rv /Volumes/Music /Volumes/Backup/Music
    cp -rv /Volumes/"Mass Storage" /Volumes/Backup/"Mass Storage"

    touch /Volumes/Backup/.dummy; hdiutil eject `disktool -l | grep Backup | awk '{ print substr($0,20,7) }'`

    In my case it mounts my external hard drive, then copies my home directory to the external, then copies my Music, and Mass Storage partitions to the external then unmounts the drive, just replace the directories or volumes with whatever you want. Ps make sure the first and last lines are one line.

    3. Press control+x and then y for yes.

    4. Next we have to set permissions type chmod u+x backup.sh

    5. last but not least run your script. cd to the directory that the script is in and type ./backup.sh, thats's it.

    All I have to do now is figure out how to run it automatically, Cron would probably be the eaisest, just have to remember how.
     
  10. mrichmon macrumors 6502a

    Joined:
    Jun 17, 2003
    #10
    You probably want to use ditto -rsrc rather than cp to copy your files. cp doesn't correctly copy resource forks or the "OS X" file attributes (such as used on hidden files).
     
  11. todd2000 thread starter macrumors 68000

    Joined:
    Nov 14, 2005
    Location:
    Danville, VA
    #11
    Thanks I'll try that, you wouldn't happen to know how to get cron to run it automatically, I tried editing /etc/crontab as root and it doesn't work, I even downloaded Cronnix which is a GUI to edit my crontab, and that didn't work either. Im running tiger
     
  12. mrichmon macrumors 6502a

    Joined:
    Jun 17, 2003
    #12
    crontab should only be edited using the crontab command. However, as I noted in a previous post, this whole scripting arrangement that you have isn't the safest way to spin down your drives.
     
  13. todd2000 thread starter macrumors 68000

    Joined:
    Nov 14, 2005
    Location:
    Danville, VA
    #13
    Sorry I missed your first post I don't want to spin down all of my drives just the external, I also wan't to unmount it when it's not being used. Why is unmounting it with this scrip not safe?
     
  14. mrichmon macrumors 6502a

    Joined:
    Jun 17, 2003
    #14
    Well, more like unnecessary and a nasty kludge to achieve something that already has other mechanisms to achieve it. I folded that into "not safe".

    Though I cannot come up with a situation where spining down the internal drives would be a problem. But each to his own.
     

Share This Page