Bash update cdrom status
Johnny Rosenberg
gurus.knugum at gmail.com
Sat Nov 23 23:41:47 UTC 2013
Let's say I have a cd-r/w in my cd burner. It's not empty:
# Variables
CdRom="/dev/sr0"
# Functions
HasMedia () {
udisks --show-info "${CdRom}" | grep "has media.*1" > /dev/null
return $?
}
IsNotEmpty () {
udisks --show-info "${CdRom}" | grep "blank.*0" > /dev/null
return $?
}
# End of code
Now:
$ if IsNotEmpty; then echo "Not empty"; else echo "Empty"; fi
Not empty
$
So far, so good. Now I erase the disc:
umount "${CdRom}"
cdrecord blank=fast dev="${CdRom}"
When finished:
$ if IsNotEmpty; then echo "Not empty"; else echo "Empty"; fi
Not empty
$
So I eject the disc:
eject $CdRom
Then I insert it again and wait. Meanwhile:
$ if HasMedia; then echo "Disc found"; else echo "Disc missing"; fi
Disc missing
$ if HasMedia; then echo "Disc found"; else echo "Disc missing"; fi
Disc missing
$ if HasMedia; then echo "Disc found"; else echo "Disc missing"; fi
Disc missing
$ if HasMedia; then echo "Disc found"; else echo "Disc missing"; fi
Disc found
$
Good, disc found. Is it empty?
$ if IsNotEmpty; then echo "Not empty"; else echo "Empty"; fi
Empty
$
Great! But how can I do this without ejecting the disc? Is there some ”disc
status update” thing to do, to make the cd reader re-read the disc somehow?
Johnny Rosenberg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20131124/d27c73f2/attachment.html>
More information about the ubuntu-users
mailing list