udev and zenity

Hi,

I cant get it working.
How do I use zenity from udev in SLES?
The udev rule is correct and runs the script one time.
But only if I disable the zenity (# before the export DISPLAY parameter and deleting the “|” before zenity starts).

I’m also able to run that script from terminal with zenity.

At the moment I’m really frustated. May you can help me fixing this. this would be aweseome.

I’m pretty sure the problem is because udev is running as root. And root never starts the x server. but why can I run tha script from terminal using sudo? isn’t it the same?

tes.sh script:

#!/bin/bash


export DISPLAY=:0


FILES=/etc/sysconfig/network/ifcfg-eth*
PATH_TO_LOG=/home/admin/Desktop/monitor.log
PATH_TO_ETH_TEMPLATE=/home/admin/Desktop/ifcfg-ethx
MANUFACTURE="Intermec Mobile Computer"
COUNT=0
MAXDEVS=1
FTP_USER=intermec
FTP_PASSWORD=cr52401
PATH_LOCAL_TO=/home/admin/erfassung.txt
FTPLOG=/home/admin/ftplogfile
FTP_SUCCESS_MSG="226 Transfer complete"
MOBILE_IP_START=169.254.2.
MOBILE_IP=""


(
#
# get the correct eth interface 
#


echo "5"; sleep 1
echo "# USB Gerät wird gesucht"; sleep 1




    # check if there the last eth was renamed and save the correct eth number to var
    # mapping to eth55 is set in custom udev rule


    LAST_USB_ETH_VAR=$(dmesg | tail -5 |grep renamed | grep -oe "eth. to eth.." | grep -oe "to eth.." | grep -oe "eth.." | xargs)


    # if it was not renamed check for rndis error


        if [  "$LAST_USB_ETH_VAR" == "" ]; then
            LAST_USB_ETH_VAR=$(dmesg | tail -5 | grep "RNDIS init failed"  | grep -oe "-3.")
            echo "Netzwer Interface war nicht ETH55 sondern: $LAST_USB_ETH_VAR" >> $PATH_TO_LOG
            
            if [  "$LAST_USB_ETH_VAR" == "-32" ]; then
                echo "RNDIS failed. Skript beendet: $LAST_USB_ETH_VAR" >> $PATH_TO_LOG
                echo "99"; sleep 1
                echo "# Gerät nicht korrekt erkannt. Bitte Gerät trennen, 60 Sekunden warten und erneut verbinden."; sleep 5
                exit
            fi
            
        fi    


    # if it was not renamed check for the last eth number that was registerd


        if [  "$LAST_USB_ETH_VAR" == "" ]; then
            LAST_USB_ETH_VAR=$(dmesg | grep register | tail -1 | grep -oe "eth.")
        fi


    #LAST_USB_ETH_VAR=$(dmesg | grep register | tail -1 | grep -oe "eth.")
    echo "letztes Netzwerkinterface von USB Gerät: $LAST_USB_ETH_VAR" >> $PATH_TO_LOG


    echo "20"; sleep 1
    echo "# USB Gerät gefunden auf $LAST_USB_ETH_VAR"; sleep 1
    echo "USB Gerät gefunden auf: $LAST_USB_ETH_VAR" >> $PATH_TO_LOG


    # get if interface ETHxx is up and which IP is configured


    # get IP from ETHxx interface from PC
    IP_AD_PC=$(ip r s | grep $LAST_USB_ETH_VAR | grep -oe "src 169.254.2..." | grep -oe "169.254.2...")


    if [  "$IP_AD_PC" == "" ]; then
        echo "25"; sleep 1
        echo "# konfiguriere Netzwerkadapter $LAST_USB_ETH_VAR"; sleep 1
        echo "konfiguriere Netzwerkadapter $LAST_USB_ETH_VAR" >> $PATH_TO_LOG


        cp $PATH_TO_ETH_TEMPLATE /etc/sysconfig/network/ifcfg-$LAST_USB_ETH_VAR


        echo "30"; sleep 1
        echo "# starte Netzwerkadapter $LAST_USB_ETH_VAR"; sleep 1
        echo "starte Netzwerkadapter $LAST_USB_ETH_VAR" >> $PATH_TO_LOG


        rcnetwork restart $LAST_USB_ETH_VAR
        sleep 4
        IP_AD_PC=$(ip r s | grep $LAST_USB_ETH_VAR | grep -oe "src 169.254.2..." | grep -oe "169.254.2...")
    fi
        
    echo "35"; sleep 1
    echo "# Interface ist konfiguriert. Lokale IP ist: $IP_AD_PC"; sleep 10
    echo "Interface ist konfiguriert. Lokale IP ist: $IP_AD_PC" >> $PATH_TO_LOG


#IP_AD_PC=$(ifconfig "$LAST_USB_ETH_VAR" | grep "inet Adresse" | cut -d: -f2 | grep -oe "169.254.2..." | xargs)
#echo "ip schon vorhanden: $IP_AD_PC" >> $PATH_TO_LOG




# getting ip from mobile device


MOBILE_START_END_IP=0




while  ! ping -c 1 $MOBILE_IP_START$MOBILE_START_END_IP;   do
    echo "40"; sleep 1
    echo "# suche MDE auf: $MOBILE_IP_START$MOBILE_START_END_IP"; sleep 1
    echo "suche MDE auf: $MOBILE_IP_START$MOBILE_START_END_IP" >> $PATH_TO_LOG
    let MOBILE_START_END_IP++


    # ignore local eth ip from pinging    
    if [ "$MOBILE_IP_START$MOBILE_START_END_IP" == "$IP_AD_PC" ]; then
        let MOBILE_START_END_IP++
    fi
    
    if [ "$MOBILE_START_END_IP" == "10" ]; then
        echo "99"; sleep 1
        echo "# IP von MDE nicht gefunden. Bitte Gerät trennen, 60 Sekunden warten und erneut verbinden."; sleep 5
        echo "IP von MDE nicht gefunden. Bitte Gerät trennen, 60 Sekunden warten und erneut verbinden" >> $PATH_TO_LOG
        exit
    fi
done


MOBILE_IP=$MOBILE_IP_START$MOBILE_START_END_IP


echo "60"; sleep 1
echo "# IP vom MDE gefunden: $MOBILE_IP"; sleep 1
echo "IP vom MDE gefunden: $MOBILE_IP" >> $PATH_TO_LOG


echo "70"; sleep 1
echo "# hole Datei"; sleep 1
echo "hole Datei" >> $PATH_TO_LOG


ftp -inv $MOBILE_IP <<! > $FTPLOG
    user $FTP_USER $FTP_PASSWORD
    binary
    cd /Datensammler/Daten
    get Erfassung.txt $PATH_LOCAL_TO
    bye
!
    
    


    if fgrep "$FTP_SUCCESS_MSG" $FTPLOG ; then
        echo "100"; sleep 1
        echo "# Datei wurde nach $PATH_LOCAL_TO übertragen"; sleep 1
        echo "Datei wurde nach $PATH_LOCAL_TO übertragen" >> $PATH_TO_LOG
    else
        echo "99"; sleep 1
        echo "# Übertragung fehlgeschlagen"; sleep 1
        echo "Übertragung fehlgeschlagen" >> $PATH_TO_LOG
        exit
    fi


: "
#count all ethernet interfaces
#COUNT_ETH_INT=$(find /etc/sysconfig/network -type f -name "ifcfg-eth*" | wc -l)


echo "aktuelle Anzahl ETH Geräte: $COUNT_ETH_INT" >> $PATH_TO_LOG


# checks if there are more than $MAXDEVS Intermec devices connected
# but only if there are network interfaces


if [ $COUNT_ETH_INT -gt 0 ]; then


    for f in $FILES
    do
        source $f
            if  [ "$NAME" == "$MANUFACTURE" ]; then
            COUNT=$(($COUNT +1))
            fi
    done


    echo "bereits verbundene Geräte von Intermec/Honeywell: $COUNT" >> $PATH_TO_LOG


else
    cp $PATH_TO_ETH_TEMPLATE /etc/sysconfig/network/ifcfg-$LAST_USB_ETH_VARB
    ifup $COUNT_ETH_INT
    echo "$COUNT_ETH_INT wurde konfiguriert und gestartet" >> $PATH_TO_LOG
    


fi


#if [ $COUNT > $MAXDEVS ]; then
#fi


"
) |
zenity --progress \\
    -- title="Update System Log" \\
    --text="scanning "\\
    --percentage=0 


if [ "$?" = -1 ]; then
    zenity --error \\
    --text="failed"
fi
exit 0

test.rules

[CODE]SUBSYSTEM==“usb”, ATTR{idVendor}==“067e”, ATTR{idProduct}==“1003”, ATTR{serial}==“0040056a-0e9d-0801-1240-01060000d201”, ACTION==“add”, RUN+="/usr/test.sh"

[/CODE]

voglsafe,

It appears that in the past few days you have not received a response to your
posting. That concerns us, and has triggered this automated reply.

These forums are peer-to-peer, best effort, volunteer run and that if your issue
is urgent or not getting a response, you might try one of the following options:

Be sure to read the forum FAQ about what to expect in the way of responses:
http://forums.suse.com/faq.php

If this is a reply to a duplicate posting or otherwise posted in error, please
ignore and accept our apologies and rest assured we will issue a stern reprimand
to our posting bot…

Good luck!

Your SUSE Forums Team
http://forums.suse.com