>ls -1 /dev/sd* /dev/sda /dev/sda1 /dev/sdb /dev/sdb1 /dev/sdc /dev/sdc1 /dev/sdd /dev/sdd1 /dev/sde /dev/sde1 /dev/sdf /dev/sdg /dev/sdh /dev/sdi
>ls -1 /dev/sd* /dev/sda /dev/sda1 /dev/sdb /dev/sdb1 /dev/sdc /dev/sdc1 /dev/sdd /dev/sdd1 /dev/sde /dev/sde1 /dev/sdf /dev/sdg /dev/sdh /dev/sdh1 /dev/sdi
>udevadm info -a -n /dev/sdh1 Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device. looking at device '/devices/pci0000:00/0000:00:02.1/usb1/1-1/1-1:1.0/host10/target10:0:0/10:0:0:2/block/sdh/sdh1': KERNEL=="sdh1" SUBSYSTEM=="block" DRIVER=="" ATTR{partition}=="1" ATTR{start}=="2048" ATTR{size}=="153600" ATTR{ro}=="0" ATTR{alignment_offset}=="0" ATTR{discard_alignment}=="0" ATTR{stat}==" 146 4 738 319 0 0 0 0 0 319 319" ATTR{inflight}==" 0 0" looking at parent device '/devices/pci0000:00/0000:00:02.1/usb1/1-1/1-1:1.0/host10/target10:0:0/10:0:0:2/block/sdh': KERNELS=="sdh" SUBSYSTEMS=="block" DRIVERS=="" ATTRS{range}=="16" ATTRS{ext_range}=="256" ATTRS{removable}=="1" ATTRS{ro}=="0" ATTRS{size}=="7745536" ATTRS{alignment_offset}=="0" ATTRS{discard_alignment}=="0" ATTRS{capability}=="51" ATTRS{stat}==" 1352 1239 73856 8882 4 18 22 735 0 3608 9615" ATTRS{inflight}==" 0 0" ATTRS{events}=="media_change" ATTRS{events_async}=="" ATTRS{events_poll_msecs}=="-1" looking at parent device '/devices/pci0000:00/0000:00:02.1/usb1/1-1/1-1:1.0/host14/target14:0:0/14:0:0:2': KERNELS=="14:0:0:2" SUBSYSTEMS=="scsi" DRIVERS=="sd" ATTRS{device_blocked}=="0" ATTRS{type}=="0" ATTRS{scsi_level}=="0" ATTRS{vendor}=="Generic-" ATTRS{model}=="SD/MMC " ATTRS{rev}=="1.00" ATTRS{state}=="running" ATTRS{timeout}=="30" ATTRS{iocounterbits}=="32" ATTRS{iorequest_cnt}=="0x220" ATTRS{iodone_cnt}=="0x220" ATTRS{ioerr_cnt}=="0x21f" ATTRS{evt_media_change}=="0" ATTRS{queue_depth}=="1" ATTRS{queue_type}=="none" ATTRS{max_sectors}=="240" looking at parent device '/devices/pci0000:00/0000:00:02.1/usb1/1-1/1-1:1.0/host14/target14:0:0': KERNELS=="target14:0:0" SUBSYSTEMS=="scsi" DRIVERS=="" looking at parent device '/devices/pci0000:00/0000:00:02.1/usb1/1-1/1-1:1.0/host14': KERNELS=="host14" SUBSYSTEMS=="scsi" DRIVERS=="" looking at parent device '/devices/pci0000:00/0000:00:02.1/usb1/1-1/1-1:1.0': KERNELS=="1-1:1.0" SUBSYSTEMS=="usb" DRIVERS=="usb-storage" ATTRS{bInterfaceNumber}=="00" ATTRS{bAlternateSetting}==" 0" ATTRS{bNumEndpoints}=="02" ATTRS{bInterfaceClass}=="08" ATTRS{bInterfaceSubClass}=="06" ATTRS{bInterfaceProtocol}=="50" ATTRS{supports_autosuspend}=="1" ATTRS{interface}=="Bulk-In, Bulk-Out, Interface" looking at parent device '/devices/pci0000:00/0000:00:02.1/usb1/1-1': KERNELS=="1-1" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{configuration}=="CARD READER" ATTRS{bNumInterfaces}==" 1" ATTRS{bConfigurationValue}=="1" ATTRS{bmAttributes}=="80" ATTRS{bMaxPower}=="500mA" ATTRS{urbnum}=="10885" ATTRS{idVendor}=="0bda" ATTRS{idProduct}=="0151" ATTRS{bcdDevice}=="5195" ATTRS{bDeviceClass}=="00" ATTRS{bDeviceSubClass}=="00" ATTRS{bDeviceProtocol}=="00" ATTRS{bNumConfigurations}=="1" ATTRS{bMaxPacketSize0}=="64" ATTRS{speed}=="480" ATTRS{busnum}=="1" ATTRS{devnum}=="15" ATTRS{devpath}=="1" ATTRS{version}==" 2.00" ATTRS{maxchild}=="0" ATTRS{quirks}=="0x0" ATTRS{avoid_reset_quirk}=="0" ATTRS{authorized}=="1" ATTRS{manufacturer}=="Generic" ATTRS{product}=="USB2.0-CRW" ATTRS{serial}=="20060413092100000" looking at parent device '/devices/pci0000:00/0000:00:02.1/usb1': KERNELS=="usb1" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{configuration}=="" ATTRS{bNumInterfaces}==" 1" ATTRS{bConfigurationValue}=="1" ATTRS{bmAttributes}=="e0" ATTRS{bMaxPower}==" 0mA" ATTRS{urbnum}=="222" ATTRS{idVendor}=="1d6b" ATTRS{idProduct}=="0002" ATTRS{bcdDevice}=="0301" ATTRS{bDeviceClass}=="09" ATTRS{bDeviceSubClass}=="00" ATTRS{bDeviceProtocol}=="00" ATTRS{bNumConfigurations}=="1" ATTRS{bMaxPacketSize0}=="64" ATTRS{speed}=="480" ATTRS{busnum}=="1" ATTRS{devnum}=="1" ATTRS{devpath}=="0" ATTRS{version}==" 2.00" ATTRS{maxchild}=="6" ATTRS{quirks}=="0x0" ATTRS{avoid_reset_quirk}=="0" ATTRS{authorized}=="1" ATTRS{manufacturer}=="Linux 3.1.10-1.16-desktop ehci_hcd" ATTRS{product}=="EHCI Host Controller" ATTRS{serial}=="0000:00:02.1" ATTRS{authorized_default}=="1" looking at parent device '/devices/pci0000:00/0000:00:02.1': KERNELS=="0000:00:02.1" SUBSYSTEMS=="pci" DRIVERS=="ehci_hcd" ATTRS{vendor}=="0x10de" ATTRS{device}=="0x077c" ATTRS{subsystem_vendor}=="0x1043" ATTRS{subsystem_device}=="0x82e7" ATTRS{class}=="0x0c0320" ATTRS{irq}=="22" ATTRS{local_cpus}=="00000000,00000000,00000000,0000000f" ATTRS{local_cpulist}=="0-3" ATTRS{numa_node}=="0" ATTRS{dma_mask_bits}=="32" ATTRS{consistent_dma_mask_bits}=="32" ATTRS{enable}=="1" ATTRS{broken_parity_status}=="0" ATTRS{msi_bus}=="" ATTRS{companion}=="" ATTRS{uframe_periodic_max}=="100" looking at parent device '/devices/pci0000:00': KERNELS=="pci0000:00" SUBSYSTEMS=="" DRIVERS==""
SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{configuration}=="CARD READER" ATTRS{idVendor}=="0bda" ATTRS{idProduct}=="0151" ATTRS{product}=="USB2.0-CRW" ATTRS{serial}=="20060413092100000"
ACTION=="add", KERNEL=="sd?1", SUBSYSTEMS=="usb", ATTRS{configuration}=="CARD READER", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="0151"
RUN+="/root/bin/PhotoSort.sh %k"
>cat /etc/udev/rules.d/99-lumix.rules # ACTION=="add", KERNEL=="sd?1", SUBSYSTEMS=="usb", ATTRS{configuration}=="CARD READER", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="0151", RUN+="/root/bin/PhotoSort.sh %k" # #ACTION=="add", KERNEL=="sd?1", SUBSYSTEMS=="pci", ATTR{events}=="media_change", ATTRS{vendor}=="0x10de", ATTRS{device}=="0x077e", RUN+="/root/bin/PhotoSort.sh %k"
>cat /root/bin/PhotoSort.sh #!/bin/bash #/root/bin/PhotoSort.sh #requires: bash,coreutils,findutils,exiftool,sed,util-linux #cat /etc/udev/rules/99-lumix.rules ## #ACTION=="add", KERNEL=="sd?1", SUBSYSTEMS=="usb", ATTRS{configuration}=="CARD READER", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="0151", RUN+="/root/bin/PhotoSort.sh %k" ## ##ACTION=="add", KERNEL=="sd?1", SUBSYSTEMS=="pci", ATTR{events}=="media_change", ATTRS{vendor}=="0x10de", ATTRS{device}=="0x077e", RUN+="/root/bin/PhotoSort.sh %k" # udev #udevadm info -a -p $(udeadm info -q path -n /dev/sd*) udevadm info -a -n /dev/sd* #http://www.arccomm.ru/OpenSource/Dev/udev.html if [[ -z "$1" ]] then echo , echo echo $(basename "$0") Source [DestDir] echo Source - , echo DestDir - , echo , echo , .PhotoCopy echo echo - \( \) echo : echo $(basename "$0") sdd1 - /dev/sdd1. echo sdd1 .PhotoCopy echo echo $(basename "$0") . ~/Photo - \(.\) echo ~/Photo/ exit 1 # fi if [[ ${1:0:1} == "/" || ${1:0:1} == "." || ${1:0:1} == "~" ]] then # if [[ -d "$1" ]] then disk="$1" else echo exit 2 # fi else # # dev="/dev/$1" if [[ ! -e "$dev" ]] then # , ( , ) exit 0 fi # disk="/mnt/photo" fi # if [[ ! -z "$2" ]] then # photo="$2" else photo="/mnt/temp/Photo" # , fi sphoto="" # # photodir="" # -: - log="/var/log/photosort.log" # lastfiletime=0 # curfiletime=0 # - #export XAUTHORITY="/home/%username%/.Xauthority" #export DISPLAY=:0.0 #notify-send Photoes "FlashCard found" # - ? - , if [[ -n "$dev" ]] then grep -q "$disk" /etc/mtab if [[ $? -eq 0 ]] # , grep 0 then # - echo "#=- $(date -u +%Y.%m.%d\ %T) -=#" exit 10 # , - fi # if [[ ! -d "$disk" ]] then # - mkdir "$disk" &>>"$log" echo "#" "$disk" >> "$log" fi mount -t vfat -o noatime,rw,noexec,users,iocharset=utf8 "$dev" "$disk" &>> "$log" if [[ ! -e "$disk"/.PhotoCopy ]] then # , umount "$disk" &>> "$log" exit 0 # , , fi # : $2, # - ( /dev) ( root) sphoto=$(head -n1 "$disk"/.PhotoCopy) # , if [[ ${sphoto:0:1} == "/" && -d "$sphoto" ]] then # , , photo="$sphoto" fi sphoto=$(tail -n1 "$disk"/.PhotoCopy) # echo $(date -u +%Y.%m.%d\ %T) "$sphoto" >> "$log" else if [[ ! -z "$2" ]] then photo="$2" # fi log="./PhotoSort.log" # echo "#" $(date -u +%Y.%m.%d\ %T) "$photo" >> "$log" echo cd $(pwd) >> "$log" # , fi # # NB!: - , # , , # ( ) # ( - ) for file in $(find "$disk" -type f \( -name '*.JPG' -o -name '*.MOV' -o -name '*.MPG' -o -name '*.THM' -o -name '*.MP4' -o -name '*.AVI' \) -and -not -name '*_*' -and -not -name '* *') do # exiftool : # Date/Time Original : 2011:07:30 15:35:52 # 20110730153552 curfiletime=$(exiftool -DateTimeOriginal "$file" | cut -d: -f2- | sed 's/[:\ ]//g') # if [[ $curfiletime == "" ]] then curfiletime=$(exiftool -CreateDate "$file" | cut -d: -f2- | sed 's/[:\ ]//g') # fi mv "$file" $(dirname "$file")/"$curfiletime"_$(basename "$file") &>> "$log" # echo mv $(dirname "$file")/"$curfiletime"_$(basename "$file") "$file" >> "$log" # done # # ( , - - , , ) for file in $(find "$disk" -type f -name '*.JPG' -o -name '*.MOV' -o -name '*.MPG' -o -name '*.THM' -o -name '*.MP4' -o -name '*.AVI' | sort) do # exiftool , , curfiletime=$(exiftool -DateTimeOriginal "$file" | sed -r 's/^.+: ([0-9]+):([0-9]+):([0-9]+) ([0-9]+):([0-9]+):([0-9]+)/\1-\2-\3 \4:\5:\6/g') if [[ $curfiletime == "" ]] then curfiletime=$(exiftool -CreateDate "$file" | sed -r 's/^.+: ([0-9]+):([0-9]+):([0-9]+) ([0-9]+):([0-9]+):([0-9]+)/\1-\2-\3 \4:\5:\6/g') fi curfiletime=$(date -d "$curfiletime" +%s) # if (( $curfiletime - $lastfiletime > 5*60*60 )) # : 5*60*60 , then photodir=$(date -d @$curfiletime +%Y.%m.%d_%H) # if [[ ! -d "$photo"/"$photodir" ]] # - then mkdir "$photo"/"$photodir" &>> "$log" chown nobody:users "$photo"/"$photodir" &>> "$log" chmod 0777 "$photo"/"$photodir" &>> "$log" echo "#" $(date -u +%Y.%m.%d\ %T) "$photodir" >> "$log" fi lastfiletime="$curfiletime" fi echo "#" $(date -u +%Y.%m.%d\ %T) "$file" "$photo"/"$photodir"/$(basename "$file") >> "$log" echo copy "$photo"/"$photodir"/$(basename "$file") "$file" >> "$log" # - (/ , gps ) mv "$file" "$photo"/"$photodir"/ &>> "$log" chown nobody:users "$photo"/"$photodir"/$(basename "$file") &>> "$log" chmod 0666 "$photo"/"$photodir"/$(basename "$file") &>> "$log" done if [[ -n "$dev" ]] then echo $(date -u +%Y.%m.%d\ %T) >> "$log" # umount "$disk" &>> "$log" fi exit 0
curfiletime=$(exiftool -DateTimeOriginal "$file" | cut -d: -f2- | sed 's/[:\ ]//g')
curfiletime=$(exiftool -DateTimeOriginal "$file" | sed -r 's/^.+: ([0-9]+):([0-9]+):([0-9]+) ([0-9]+):([0-9]+):([0-9]+)/\1-\2-\3 \4:\5:\6/g')
./PhotoSort.sh sdh1
so the script is called from udev to sort the sdh1 disk. In this case, the presence of a file with settings in its root will be checked. The disk was transferred to us or the directory is determined by the first character: if it will be ~ / or. - means a directory, otherwise - a disk. ./PhotoSort.sh ~/AllFromParty
as well, you can sort all the photo and video files from all the directories nested in ~ / AllFromParty (including himself). Everything will be saved to the default directory specified in the script (photo = "/ mnt / temp / Photo"). If there were files from several cameras in the source directory, then there may be some dissynchronization in the file names due to the fact that the time between the cameras was not synchronized, or even never exhibited. What can cause the distribution of files from different cameras in different directories. Then, before performing the sorting, you need to adjust the time in the EXIF ​​tags: exiftool "-DateTimeOriginal + = 00.00.0000 02:37:30" * .JPG - will shift the time in the DateTimeoriginal tag by 2:37:30 to the future for all JPG files from the current directory. ./PhotoSort.sh ~/AllFromParty /media/backup/Photoes
the same as above, but everything will be saved in the / media / backup / Photoes directorySource: https://habr.com/ru/post/158371/
All Articles