[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Calling a script after USB scanner is plugged



Hello,

I want to call a script after I plugged my USB scanner. I use udev for this by 
adding a rule

rd@blackbox:/etc/udev/rules.d$ cat z_local.rules
SYSFS{idVendor}=="1606", SYSFS{idProduct}=="0010", MODE="0664", 
GROUP="scanner", NAME="umax%n", RUN+="/usr/local/bin/umax1220u start", 
rd@blackbox:/etc/udev/rules.d$

This calls then the umax1220u script:

rd@blackbox:/usr/local/bin$ cat umax1220u
#!/bin/sh
set -vx
# example for a DEVICE: /proc/bus/usb/001/004

  echo umax1220u $DEVICE $* >> /tmp/usb.log
  export >> /tmp/usb.log
  ACTION=$1

#  if [ -z $DEVICE ]; then exit 0; fi

  case $ACTION in
  start)
          echo "UMAX 1220u scanner added"
  #        DEV=umax1220u:libusb:`echo $DEVICE|cut -d / -f 5`:`echo $DEVICE|
cut -d / -f 6`
          DEV=`scanimage -L|cut -f 2 -d \\\`|cut -f1 -d \'`
          echo started: $DEV >> /tmp/usb.log
          # example for a DEV umax1220u:libusb:001:006
          (sleep 20 
&& /usr/bin/scanimage --lamp-off --device=$DEV --dont-scan) &
          ;;
  stop)
          echo "UMAX 1220u scanner removed"
          ;;
  esac
rd@blackbox:/usr/local/bin$

When I plug my scanner with this config, it seems an infinite number of 
umax1220u scripts are started in a sequence (i.e. not in parallel, when one 
is completed the next one starts).

Initial analysis shows that scanimage causes in syslog

Apr 22 22:07:48 blackbox kernel: ppdev0: registered pardevice
Apr 22 22:07:48 blackbox kernel: ppdev0: unregistered pardevice
Apr 22 22:07:50 blackbox kernel: ppdev0: registered pardevice
Apr 22 22:07:50 blackbox kernel: ppdev0: unregistered pardevice

This might then kick off another umax1220u via udev (?). An this would then 
loop.

Does anybody know how I could get rid of this event?

Does anybody know a better way to get the script started which switches the 
scanner lamp off?

Thanks,
Rainer

-- 
Rainer Dorsch
Lärchenstr. 6
D-72135 Dettenhausen
07157-734133
email: rdorsch@web.de
jabber: rdorsch@jabber.org
GPG Fingerprint: 5966 C54C 2B3C 42CC 1F4F  8F59 E3A8 C538 7519 141E
Full GPG key: http://pgp.mit.edu/


Reply to: