unmount a device in bash script that's in use by the script?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
linx255
Level 5
Level 5
Posts: 668
Joined: Mon Mar 17, 2014 12:43 am

unmount a device in bash script that's in use by the script?

Post by linx255 »

I need to mount and unmount a device from my script, which I do using:

Code: Select all

sudo mount -ro noatime,discard $device $location
or

Code: Select all

sudo mount -o noatime,discard $device $location
and

Code: Select all

sudo umount $device
but $device is in use so I have to:

Code: Select all

sudo fuser -km $device; sudo umount $device
but this kills my script too because apparently $device is in use by the script.

I don't know why $device is in use by the script, but I don't want it to be.

And $device was also in use by VLC for some weird reason, so my VLC gets killed against my wishes.

It seems whatever I mount latches on to different programs so I can't unmount it.

Scratching my head...How do I get around this?

Thanks
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
- I'm running Mint 18 Mate 64-bit
- 4.15.0-34-generic x86_64
- All my bash scripts begin with #!/bin/bash
User avatar
xenopeek
Level 25
Level 25
Posts: 29509
Joined: Wed Jul 06, 2011 3:58 am

Re: unmount a device in bash script that's in use by the scr

Post by xenopeek »

What are you doing between mounting the device, and later in your script unmounting it? The clue is likely there. Perhaps you cd into the mountpoint? That prevents unmounting.
Image
Locked

Return to “Scripts & Bash”