0

How can I unmount a USB drive using a script located on that drive? The device appears busy when the script is running,

3
  • 1
    You should be able to make the script copy itself to /tmp or similar, run and detach the copy and exit itself. Otherwise you will still have a open file descriptor on the drive blocking unmounting.
    – chronitis
    Oct 24, 2013 at 10:02
  • @chronitis: how do I "run and detach the copy" in bash?
    – antonio
    Oct 24, 2013 at 10:08
  • Normally a script owns any other scripts it starts, and does not exit until they do, even if they are started with script &. You want the parent script to really exit before the child script unmounts the drive, so I think you have to use nohup or similar to ensure the child survives the parent exiting. I'm not certain about the exact semantics however, which is why this is a comment and not an answer.
    – chronitis
    Oct 24, 2013 at 10:31

1 Answer 1

1

First attempt with &

#!/bin/sh -xv

#Get  device where I am located  
DEV=$(df -k "$0" | tail -1 | awk '{ print $1 }')
echo $DEV

#Create umount script 
echo '#!/bin/sh -xv' >/tmp/udisk.tmp
echo "umount $DEV" >>/tmp/udisk.tmp
cat /tmp/udisk.tmp
chmod +x /tmp/udisk.tmp

#Run the script 
/tmp/udisk.tmp & 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .