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.



#!/bin/bash

PATH=${PATH}:/sbin:/usr/sbin

dr=($(drutil status | grep -i 'type:'))
devtype=${dr[1]}
device=($(mount | grep ${dr[3]}))
if [ $devtype = "No" ]
then echo No disk found. Sorry! >&2
exit 1;
fi
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.

Comments

Popular posts from this blog

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

How to enable root login in gnome on Debian 6 or 7