[clug] Help please with running a script on an event

jhock jhock at iinet.net.au
Thu Jan 17 07:00:10 UTC 2019


Many thanks to Brenton and David for their replies.

I have looked at the suggested web and it was very helpful although I
just can't get the script to run. I think it's something to do with the
entry in the udev rules file. Here is some information.

When I connect my phone and run:

$ udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[18431.513361] add      /devices/pci0000:00/0000:00:14.0/usb1/1-
1 
(usb)
KERNEL[18431.519451] add      /devices/pci0000:00/0000:00:14.0/usb1/1-
1/1-1:1.0 (usb)
KERNEL[18431.519573] bind     /devices/pci0000:00/0000:00:14.0/usb1/1-
1 
(usb)
UDEV  [18431.530918] add      /devices/pci0000:00/0000:00:14.0/usb1/1-
1 
(usb)
UDEV  [18431.534169] add      /devices/pci0000:00/0000:00:14.0/usb1/1-
1/1-1:1.0 (usb)
UDEV  [18431.535664] bind     /devices/pci0000:00/0000:00:14.0/usb1/1-
1 
(usb)
KERNEL[18431.566670] bind     /devices/pci0000:00/0000:00:14.0/usb1/1-
1/1-1:1.0 (usb)
UDEV  [18431.568292] bind     /devices/pci0000:00/0000:00:14.0/usb1/1-
1/1-1:1.0 (usb)


I then run:

$ lsblk
NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
<snip/>
nvme0n1        259:0    0 335.4G  0 disk  
├─nvme0n1p1    259:1    0   512M  0 part  /boot/efi
├─nvme0n1p2    259:2    0 319.1G  0 part  /
└─nvme0n1p3    259:3    0  15.8G  0 part  
  └─cryptswap1 253:0    0  15.8G  0 crypt [SWAP]

I then run:

$ udevadm info /dev/nvme0n1p1
P:
/devices/pci0000:00/0000:00:1d.0/0000:6e:00.0/nvme/nvme0/nvme0n1/nvme0n
1p1
N: nvme0n1p1
S: disk/by-id/nvme-INTEL_SSDPEKKF360G7H_BTPY72200WPY360E-part1
S: disk/by-id/nvme-eui.0000000001000000e4d25cf3cccc4d01-part1
S: disk/by-partlabel/EFI\x20System\x20Partition
S: disk/by-partuuid/13e09633-6c8c-4d2a-a1e1-8d265430ffbd
S: disk/by-path/pci-0000:6e:00.0-nvme-1-part1
S: disk/by-uuid/05CE-D2F4
E: DEVLINKS=/dev/disk/by-partuuid/13e09633-6c8c-4d2a-a1e1-8d265430ffbd
/dev/disk/by-id/nvme-INTEL_SSDPEKKF360G7H_BTPY72200WPY360E-part1
/dev/disk/by-partlabel/EFI\x20System\x20Partition /dev/disk/by-
path/pci-0000:6e:00.0-nvme-1-part1 /dev/disk/by-uuid/05CE-D2F4
/dev/disk/by-id/nvme-eui.0000000001000000e4d25cf3cccc4d01-part1
E: DEVNAME=/dev/nvme0n1p1
E:
DEVPATH=/devices/pci0000:00/0000:00:1d.0/0000:6e:00.0/nvme/nvme0/nvme0n
1/nvme0n1p1
E: DEVTYPE=partition
E: ID_FS_TYPE=vfat
E: ID_FS_USAGE=filesystem
E: ID_FS_UUID=05CE-D2F4
E: ID_FS_UUID_ENC=05CE-D2F4
E: ID_FS_VERSION=FAT32
E: ID_MODEL=INTEL SSDPEKKF360G7H
E: ID_PART_ENTRY_DISK=259:0
E: ID_PART_ENTRY_NAME=EFI\x20System\x20Partition
E: ID_PART_ENTRY_NUMBER=1
E: ID_PART_ENTRY_OFFSET=2048
E: ID_PART_ENTRY_SCHEME=gpt
E: ID_PART_ENTRY_SIZE=1048576
E: ID_PART_ENTRY_TYPE=c12a7328-f81f-11d2-ba4b-00a0c93ec93b
E: ID_PART_ENTRY_UUID=13e09633-6c8c-4d2a-a1e1-8d265430ffbd
E: ID_PART_TABLE_TYPE=gpt
E: ID_PART_TABLE_UUID=7b1cda40-6708-4f3a-9045-c6d582bdb161
E: ID_PATH=pci-0000:6e:00.0-nvme-1
E: ID_PATH_TAG=pci-0000_6e_00_0-nvme-1
E: ID_SERIAL=INTEL SSDPEKKF360G7H_BTPY72200WPY360E
E: ID_SERIAL_SHORT=BTPY72200WPY360E
E: ID_WWN=eui.0000000001000000e4d25cf3cccc4d01
E: MAJOR=259
E: MINOR=1
E: PARTN=1
E: PARTNAME=EFI System Partition
E: SUBSYSTEM=block
E: TAGS=:systemd:
E: UDISKS_IGNORE=1
E: USEC_INITIALIZED=1422073


I'm assuming that the smartphone's DEVNAME is /dev/nvme0n1p1 so my
entry in the /etc/udev/rules.d/80-Xiaomi_Backup.rules file looks like
this:

SUBSYSTEM=="usb", ACTION=="add",
ENV{DEVNAME}=="/dev/nvme0n1p1",  RUN+="/home/jo
hn/xiaomiBackup.sh"

I then ran:

$ sudo udevadm control --reload

and then connected my phone.

The /home/john/xiaomiBackup.sh file should touch a file but it doesn't
when I connect my phone. It does if I run the script as myself or root.

I'm wondering if I'm misinterpreting the DEVNAME environment variable?

Many thanks in advance for any help.


John.


On Tue, 2019-01-15 at 18:16 +1100, Brenton Ross via linux wrote:
> You may need to set up a udev rule.
> 
> Here is an intro; 
> https://www.tecmint.com/udev-for-device-detection-management-in-linux/
> 
> Brenton
> 
> On Tue, 2019-01-15 at 14:32 +1100, jhock via linux wrote:
> > Hi all,
> > 
> > I have written a quick bash script to backup my smartphone using
> > the 
> > 
> > `adb backup -all -apk -obb -shared -f $fileName`
> > 
> > command. I would like to automatically run this script on the event
> > of
> > connecting my smartphone. Can anyone tell me how to run a script or
> > prompt me to run a script on the connection of a smartphone via
> > cable?
> > 
> > Thanks in advance for any help.
> > 
> > 
> > John.
> > 
> > 
> > 




More information about the linux mailing list