Eu fiz uma pequena regra do udev que lança um script que faz um arquivo do meu diretório ~/Documents
.
Isso faz o trabalho, mas quando eu leio o arquivo de log, parece que o script de arquivamento é executado 3 vezes quando eu conecto minha chave.
Aqui está minha regra:
ACTION=="add", SUBSYSTEMS=="usb", DRIVERS=="usb", ATTRS{idVendor}=="0951", ATTRS{idProduct}=="1642", RUN+="/bin/sh /root/auto-archive"
Aqui está meu script:
#! /bin/sh
sleep 5
# test if awesome is running
if ps aux | grep -v launch | grep -v grep | grep awesome
then
echo awesome is running >> /home/purplepsycho/log
else
# echo awesome not running another guy must be logged
exit
fi
if mount | grep /media/usb
then
echo /media/usb already mounted >> /home/purplepsycho/log
exit
fi
# mount key
echo mounting... >> /home/purplepsycho/log
/usr/bin/sudo -u purplepsycho mount /media/usb
# test if mount have been succesful
if [ $? -ne 0 ]
then
echo mount failed >> /home/purplepsycho/log
exit
fi
# archive dir
ARC_DIR="/media/usb/archive"
# make directory
mkdir -p $ARC_DIR
# archive name
NAME=$(date +"archive-%Y-%m-%d.tgz")
# test if an archive already exists for today
if [ -f $ARC_DIR/$NAME ]
then
echo archive file already exists for today >> /home/purplepsycho/log
exit
fi
# initialize log file
echo $NAME > $ARC_DIR/files.txt
# make the archive
tar -zcvf $ARC_DIR/$NAME /home/purplepsycho/Documents/* >> $ARC_DIR/files.txt
Alguma ideia? Obrigado.
--- Editar após o comentário do Sparhawk ---
Eu corro udevadm
na minha chave:
udevadm info -a -p $(udevadm info -q path -n /dev/sbd)
Que deu:
looking at device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0/block/sdb':
KERNEL=="sdb"
SUBSYSTEM=="block"
DRIVER==""
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0':
KERNELS=="4:0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0/host4/target4:0:0':
KERNELS=="target4:0:0"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0/host4':
KERNELS=="host4"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0':
KERNELS=="1-1:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="usb-storage"
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1':
KERNELS=="1-1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{idVendor}=="0951"
ATTRS{idProduct}=="1642"
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1':
KERNELS=="usb1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{idVendor}=="1d6b"
ATTRS{idProduct}=="0002"
looking at parent device '/devices/pci0000:00/0000:00:1d.7':
KERNELS=="0000:00:1d.7"
SUBSYSTEMS=="pci"
DRIVERS=="ehci-pci"
ATTRS{irq}=="23"
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
Eu tentei escrever regras apenas com base em:
KERNELS=="1-1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{idVendor}=="0951"
ATTRS{idProduct}=="1642"
e
KERNELS=="usb1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{idVendor}=="1d6b"
ATTRS{idProduct}=="0002"
O resultado é o mesmo: o script é chamado várias vezes ...