I have a task in automator to make my backup, it runs shell script code, lot of code is working well but the unmount command doesn't works, I don't get unmount the unit after backup.

I checked to run my command successfully from terminal, It unmounts my drive well, all fine, but when It runs from my bash script in automator It doesn't unmounts the unit, no errors, it runs well, but it doesn't unmount. :(

My command used is: sudo diskutil unmountDisk disk3;

I have try with and without sudo, and I have the same problem.

I have tried diskutil eject command and same thing, it unmounts the unit typing it at hand from terminal, but from my automator shell script code it doesn't.

Any idea is very welcome.

up vote 1 down vote accepted

When run from Automator how are you inputting your password when prompted by sudo? You're probably not being prompted if you're just running it the same way as if in Terminal.

You'll need to add some AppleScript code and run it via osascript so you're prompted for an Admin password:

osascript -e 'do shell script "sudo diskutil unmountDisk disk3" with administrator privileges'
  • Thank you, your solution works!. I didn't need sudo for it, so it is better. But sometimes my usb change the dev name. What command could I use to get the dev name associated to a volume name? – bunset May 28 '16 at 18:53
  • 1
    @bunset, You can also use diskutil unmountDisk $MountPoint, e.g diskutil unmountDisk /Volumes/Untitled or diskutil unmountDisk $UUID. See the DEVICES section in the diskutil man page. "A device parameter to any of the above commands (except where explicitly required otherwise) is usually any of the following:", which you can read further in the man page. – user3439894 May 28 '16 at 23:34

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.