Bash update cdrom status

Colin Law clanlaw at googlemail.com
Sun Nov 24 08:44:47 UTC 2013


On 23 November 2013 23:41, Johnny Rosenberg <gurus.knugum at gmail.com> wrote:
>
> 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?

What does the udisks command in your script show before and after blanking it?

Colin




More information about the ubuntu-users mailing list