bash script in udev rule is taking longer time, normal in terminal will run quickly und success

66 views Asked by At

in my case i have no idea what goes wrong.

i have a custom udev.rule

/etc/udev/rules.d/99-printer.rules ACTION=="add", SUBSYSTEM=="usb", RUN+="/usr/local/bin/reg_printer.sh"

this will fires if my printer switch from off to on

this will be fired but resonse in journalctl -f

is Spawned process '/usr/local/bin/reg_printer.sh' [3899] is taking longer than 59s to complete

my reg_printer.sh fires a usbip script to register in config file declared devices

this will always work if i run the command in terminal

but if i run this in udev rule always become the error message and nothing happens.

here the script vom usbip

#!/bin/sh
CFG_DIR="/usr/local/etc/usbip"


help(){
    echo
    echo "Syntax error"
    echo "   $0 [bind|unbind]"
    echo
    exit 1
}


missing_file(){
    echo
    echo "$0: Can't read file '$1'"
    exit 2
}

server(){
    cmd="$1"
    CFG_FILE="$CFG_DIR/server.conf"
    test ! -r $CFG_FILE && missing_file $CFG_FILE
    
    usbip list -p -l | tr '=#' '  ' | while read _ busid _ usbid; do
    if grep -Eq "^($busid|$usbid)\$" "$CFG_FILE"; then
        usbip $cmd -b $busid
        if [ "$cmd" = "bind" ]; then
             sshpass -p password ssh -o StrictHostKeyChecking=no [email protected] 'usbip attach -r 10.0.0.10 -b 1-1'
        fi
    fi
    done
}



case $1 in
    bind)
    server bind
    ;;
    unbind)
    server unbind
    ;;
    *)
    help
    ;;
esac


i try since 2 houres with search in google to find a solution....

if i run this script from commandline all things go ok...

have anybody know the reason ?

Thanks for help

0

There are 0 answers