처음‎ > ‎지식기반‎ > ‎

RPi: UDEV Rules

81-lcd4linux.rules

SUBSYSTEM=="block", ACTION=="add", ENV{ID_MODEL_ID}=="0001", ENV{ID_VENDOR_ID}=="1403", RUN+="/usr/bin/lcd4linux"
SUBSYSTEM=="block", ACTION=="remove", ENV{ID_MODEL_ID}=="0001", ENV{ID_VENDOR_ID}=="1403", RUN+="/usr/bin/killall lcd4linux"

82-webcam.rules

ATTRS{idVendor}=="045e", ATTRS{idProduct}=="0772", SUBSYSTEM=="usb", ACTION=="add", RUN+="/usr/local/bin/start_motion.sh" ATTRS{idVendor}=="045e", ATTRS{idProduct}=="0772", SUBSYSTEM=="usb", ACTION=="remove", RUN+="/usr/local/bin/stop_motion.sh"

/usr/local/bin/start_motion.sh

#!/bin/bash
rm /root/motion.log
#non-daemon mode is more reliable with Lifecam
/usr/bin/motion -n >> /root/motion.log

/usr/local/bin/stop_motion.sh

#!/bin/bash
/etc/init.d/motion stop
/usr/bin/killall motion

99-unplug2shutdown.rules

ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c526", SUBSYSTEM=="input", ACTION=="add|remove", RUN+="/sbin/shutdown -h now"

83-motion-backup.rules

ATTRS{idVendor}=="05dc", ATTRS{idProduct}=="a207", ACTION=="add", SYMLINK+="backup", RUN+="/usr/local/bin/backup-thumb.sh"
  • apt-get install usbmount

/usr/local/bin/backup-thumb.sh

#!/bin/bash

NOTIFYUSER="pi"
MAINDIR="/tmp/motion/"
BACKUPDIR="/media/usb0"
#DEVICE="/dev/backup"

su $NOTIFYUSER alt-notify-send backup "Waiting for things to settle" 0
sleep 5

su $NOTIFYUSER alt-notify-send backup "Starting backup" 0

#echo "$(date) - Mounting $DEVICE to $BACKUPDIR" > /tmp/backup.log
#mount $DEVICE $BACKUPDIR >> /tmp/backup.log 2>&1

echo "$(date) - Staring rsync of $MAINDIR to $BACKUPDIR" >> /tmp/backup.log
rsync -arvuz --inplace --delete $MAINDIR $BACKUPDIR >> /tmp/backup.log 2>&1

#echo "$(date) - Mounting $DEVICE to $BACKUPDIR" >> /tmp/backup.log
#umount $BACKUPDIR >> /tmp/backup.log 2>&1

su $NOTIFYUSER alt-notify-send backup "Backup completed" 0

Comments