• # essai par rapports aux variables d'environnement etc.

    Posté par . En réponse au message détecter le branchement ou l'allumage d'un périphérique USB (VPI Epson). Évalué à 2. Dernière modification le 08 janvier 2026 à 13:01.

    Le script avec juste

    xinput | grep EPSON | grep -oP '(?<=id=)[0-9]+' | xargs -I % xinput map-to-output % DP-2

    fonctionne quand il est lancé par l'utilisateur prn
    Il fonctionne aussi quand l'utilisateur prn le lance après un sudo -i ou après un sudo

    Il ne fonctionne pas quand il est lancé par la règle udev.

    J'ai essayé de voir ce qui change en le remplaçant par

    #!/bin/sh
    LOGFILE="/tmp/test.log"
    echo "-------------------$(date)-----------------------------" >> "$LOGFILE" 2>&1
    echo "whoami : $(whoami)" >> "$LOGFILE" 2>&1
    echo "id : $(id)" >> "$LOGFILE" 2>&1
    echo "pwd : $(pwd)" >> "$LOGFILE" 2>&1
    echo "DISPLAY : ${DISPLAY}" >> "$LOGFILE" 2>&1
    echo "XAUTHORITY : ${XAUTHORITY}" >> "$LOGFILE" 2>&1
    

    et selon les cas c'est assez différent :

    pour l'utilisateur prn :

    whoami : prn
    id : uid=1000(prn) gid=1000(prn) groupes=1000(prn),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),100(users),105(lpadmin),125(sambashare)
    pwd : /home/prn
    DISPLAY : :0.0
    XAUTHORITY : /home/prn/.Xauthority
    

    avec sudo -i :

    whoami : root
    id : uid=0(root) gid=0(root) groupes=0(root)
    pwd : /root
    DISPLAY : :0.0
    XAUTHORITY : /home/prn/.Xauthority
    

    après la règle udev :

    whoami : root
    id : uid=0(root) gid=0(root) groupes=0(root)
    pwd : /
    DISPLAY : 
    XAUTHORITY : 
    

    Pourtant quand j'essaye de "forcer" DISPLAY et XAUTHORITY ça ne marche pas ???