Automatically move photos from memory card to hard drive with udev

# create udev rule
cat < /etc/udev/rules.d/70-persistent-dcim.rules
KERNEL=="sd*1",SUBSYSTEM=="block",ATTR{partition}=="1",ACTION=="add",RUN+="/usr/sbin/mvdcim.sh \$KERNEL"
EOF

# create mvdcim.sh script
cat < /usr/sbin/mvdcim.sh
#!/bin/bash

DEVICE=/dev/\${1}
SOURCE=/mnt/DCIM/100NIKON
TARGET=/home/hafr/dcim

mount \${DEVICE} /mnt
if [ -d \${SOURCE} ]; then
mv \${SOURCE}/*.jpg \${TARGET}
chmod 666 \${TARGET}/*.jpg
eject \${DEVICE}
else
umount /mnt
fi
EOF
chmod +x /usr/sbin/mvdcim.sh

# monitor changes (optional)
udevadm monitor

# get device info (optional)
udevadm info -a -p $(udevadm info -q path -n /dev/sdb1)

# usb info
sudo lsusb -v

# device info
udevadm info --query=all --name=/dev/sdc1

# Links
http://wiki.ubuntuusers.de/UDEV