I need to mount a volume, tar the contents of the mounted volume and unmount that mounted volume, in a single shell script.So I coded as,$ cat sample.shsudo mount -o loop Sample.iso /tmp/mntcd /tmp/mnttar-cvf /tmp/sample.tar *sudo umount /tmp/mntI got the error umount: /tmp/mnt: device is busy.So I checked the$ lsof /tmp/mntIt outputs the current sh file. So I convinced myself, /tmp/mnt is busy in the current script (in this case, sample.sh).Is there any way around for (mount, tar, unmount) in the same script ?P.S : I'm able to unmount the /tmp/mnt volume once the script finishes.
Mounting and unmounting in same shell script results in error
shell script;shell;mount;tar;unmounting
You need to exit the directory to unmount it, like this: #!/bin/bashsudo mount -o loop Sample.iso /tmp/mntcd /tmp/mnttar -cvf /tmp/sample.tar *#Got to the old working directory. **NOTE**: OLDPWD is set automatically.cd $OLDPWD#Now we're able to unmount it. sudo umount /tmp/mntThat is it. 