You are not logged in.

#1 2010-06-27 12:22:42

orphius1970
Member
From: Modesto (HELL) California
Registered: 2009-02-27
Posts: 151

[solved] Dvd Drive detection in script - how?????

As the header says. Is there an easy way to detect if an unmounted disc is in my dvd drive, from within a bash script?

Last edited by orphius1970 (2010-06-28 20:11:29)


AMD Phenomx3, 4gb ram, Nvidia Gforce 9400gt,
MSI K9N2 Diamond Motherboard, Arch x86_64

Offline

#2 2010-06-27 18:00:55

simlan
Member
From: Germany
Registered: 2010-05-30
Posts: 20

Re: [solved] Dvd Drive detection in script - how?????

Maybe u could try to compare the output of

mount -l

with the contents of

/dev/dvd

or just check if /dev/dvd is readable like that:

sudo cat /dev/dvd
if [ $? -eq 0 ]
then DOSOMETHING
fi;

Offline

#3 2010-06-27 18:59:50

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,799
Website

Re: [solved] Dvd Drive detection in script - how?????

[[ ! -b /dev/sr0 ]] && echo 'zomg, drive not found!'

edit: sorry, that probably just checks that a disc is in the tray.

grep -Fq '/dev/sr0' /proc/mounts || echo 'zomg, drive not mounted!'

should check if it's actually mounted somewhere

Last edited by brisbin33 (2010-06-27 19:16:04)

Offline

#4 2010-06-27 19:21:41

orphius1970
Member
From: Modesto (HELL) California
Registered: 2009-02-27
Posts: 151

Re: [solved] Dvd Drive detection in script - how?????

Brisbin,
The first one is what I need. How would I work that into conky? I want to have a message display when a disc is on
drive or if not. Something like:
Disc
NoDisc
I know I can use the if_mounted option in conky. I really want to know if there is disk in drive, even when not mounted

First one seems to not work


NEW!
I just discovered that when a cd or dvd is inserted. Folder "/dev/dvd/by-label" is created and removed when disk is ejected.
So I have the following script.

#!/bin/bash
directory="/dev/dvd/by-label"

# bash check if directory exists
if [ -d $directory ]; then
    echo "Directory Exists"
else 
    echo "Directory does not exists"
fi

How would I alter this to work inside conky?

SOLVED IT!!

Changed script to:

#!/bin/bash
directory="/dev/dvd/by-label"

# bash check if directory exists
if [ -d $directory ]; then
    echo "+ Dvd +"
else 
    echo "- Dvd -"
fi

+ = disc in drive
- = disc not in drive
Added it to conky with ${exec script}

Last edited by orphius1970 (2010-06-28 20:11:01)


AMD Phenomx3, 4gb ram, Nvidia Gforce 9400gt,
MSI K9N2 Diamond Motherboard, Arch x86_64

Offline

Board footer

Powered by FluxBB