Page 3 of 3 FirstFirst 123
Results 21 to 22 of 22

Thread: Determine optical media type (Audio CD, DVD, blu-ray) by using UDEV and scripts

  1. #21
    Join Date
    Apr 2015
    Beans
    16

    Re: Determine optical media type (Audio CD, DVD, blu-ray) by using UDEV and scripts

    Quote Originally Posted by blm-ubunet View Post
    James
    The format of this is wrong:
    Code:
    if [ "$ID_CDROM_MEDIA_DVD"="1" ]
    change all similar instances like to style/format of below
    Code:
    if [ $ID_CDROM_MEDIA_DVD = "1" ]  or
    if [ "$ID_CDROM_MEDIA_DVD" = "1" ] or
    if [ $ID_CDROM_MEDIA_DVD == "1" ]
    Without the space, I believe it tests the return value of assignment (always true).
    So your script was going to return just dvd.

    You made a mess of the first line of script as well:


    I have found this to be a very useful resource:
    http://www.tldp.org/LDP/Bash-Beginne...ect_07_01.html
    Well well well!!

    blm-ubunet your advice is well taken, I have changed the construction of the 'if' statements to match and it is now working! , thank you.
    Keith_Helm I cant thank you enough for the posix code, this will enable me to further look into this. Thank you.

    Udev rule as follows:
    Code:
    # ID_CDROM_MEDIA_BD = Bluray
    # ID_CDROM_MEDIA_DVD = DVD
    # ID_CDROM_MEDIA_CD = CD
    ACTION=="change", SUBSYSTEMS=="scsi", KERNEL=="s[rg][0-9]*", ATTRS{vendor}=="TSSTcorp", ENV{ID_CDROM}=="?*", MODE="0660", GROUP="optical", RUN+="/usr/local/bin/DiscTypeTest3.sh"
    links to script as follows

    Code:
    #!/bin/bash
    # ID_CDROM_MEDIA_BD = Bluray
    # ID_CDROM_MEDIA_DVD = DVD
    # ID_CDROM_MEDIA_CD = CD
    MEDIA=
    if [ $ID_CDROM_MEDIA_DVD = "1" ]
    then
            MEDIA=dvd
            (
            echo "$MEDIA" >> "/var/log/DiscTypeTest.log"
            ) &
    
    
    elif [ $ID_CDROM_MEDIA_CD = "1" ]
    then
            MEDIA=cdrom
            (
            echo "$MEDIA" >> "/var/log/DiscTypeTest.log"
            ) &
    fi
    (set -o posix ; set) > "/var/log/DiscTypeTestVariables.log"
    
    produces the following output in
    Code:
    /var/log/DiscTypeTest.log
    when an audio CD is inserted and then a dvd afterwards

    Code:
    cdrom
    cdrom
    dvd
    dvd
    SOLVED
    Last edited by jlivin252; May 15th, 2015 at 12:29 AM. Reason: mistyped code

  2. #22
    Join Date
    Jan 2014
    Beans
    473
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: Determine optical media type (Audio CD, DVD, blu-ray) by using UDEV and scripts

    Great news & well solved.
    We've probably all made this mistake before & I'm likely to repeat it sometime in the future.

Page 3 of 3 FirstFirst 123

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •