What process is using your CD or DVD on *nix

Tried to eject a CD or DVD and you were told that the disk was in use and couldn't figure out what was using the disk? Use the below shell script is to findout.



dr=($(drutil status | grep -i 'type:'))
device=($(mount | grep ${dr[3]}))
if [ $devtype = "No" ]
then echo No disk found. Sorry! >&2
exit 1;
echo A $devtype is mounted on the device named $device
pids=($(sudo -p 'Please enter the administrator password:' lsof -t $device))
echo \nList of programs that may be preventing the disk to eject
ps -o pid,user,comm=COMMAND -www -p $(echo ${pids[*]} | sed 's/ /,/g')

The output is a list of the processes that lsof says is using the CD or DVD.


Popular posts from this blog

How to disable USB ports on Mac OS X Mavericks, Yosemite or El Capitan ?