You are not logged in.

#1 2015-11-12 02:19:10

pdizzle
Member
Registered: 2013-02-07
Posts: 15

[Solved] Udev rule to rsync folders on connect fails

I am stumped as to what exactly is going on here.

What I am trying to do is have my garmin watch automatically rsync to a folder on my dropbox (mounted on my filesystem), to be accessible to tapiriik.

I have made a rule, that I have verified matches the USB device I would like to sync:

#/etc/udev/rules.d/61-tapiriik.rules
ACTION=="add", KERNEL=="sd*", ATTRS{idVendor}=="0424", ATTRS{idProduct}=="2513", RUN+="/home/wash/bin/garmin_upload.sh"

the script that runs:

#/home/wash/bin/garmin_upload.sh
#!/bin/bash
rsync -v /media/GARMIN/Garmin/Activity/* /home/wash/Dropbox/Apps/tapiriik/ &> /home/wash/tester

I redirect the output to that file and tail -f /home/wash/tester to view what happens:

rsync: change_dir "/media/GARMIN/Garmin/Activity" failed: No such file or directory (2)

sent 18 bytes  received 12 bytes  60.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1165) [sender=3.1.1]

I have USB devices automount using udisks2. I (wash), not root, am the owner of /media/GARMIN. by adding ls -al /media to garmin_upload.sh I found that Udev is unable to see /media/GARMIN. I also added id so I could verify the script runs as root:

#/home/wash/bin/garmin_upload.sh
#!/bin/bash

id &> /home/wash/tester
ls -al /media &> /home/wash/tester
rsync -v /media/GARMIN/Garmin/Activity/* /home/wash/Dropbox/Apps/tapiriik &> /home/wash/tester

tail -f /home/wash/tester

uid=0(root) gid=0(root) groups=0(root)

tail: tester: file truncated
total 12
drwxr-xr-x   3 root root 4096 Nov 11 19:43 .
drwxr-xr-x  18 root root 4096 Nov  4 08:29 ..
tail: tester: file truncated
rsync: change_dir "/media/GARMIN/Garmin/Activity" failed: No such file or directory (2)

sent 18 bytes  received 12 bytes  60.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1165) [sender=3.1.1]

why is this folder not visible to the script/udev? If I run the script as root using su, it works fine. I've also tried inserting very long sleeps (10s) to make sure the script isn't ahead of the mounting.

Last edited by pdizzle (2015-11-12 05:23:23)

Offline

#2 2015-11-12 02:22:58

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [Solved] Udev rule to rsync folders on connect fails


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2015-11-12 03:07:21

pdizzle
Member
Registered: 2013-02-07
Posts: 15

Re: [Solved] Udev rule to rsync folders on connect fails

Thanks for the fast response. Very informative. I have left the script as-is but update the Udev rule to read:

ACTION=="add", KERNEL=="sd*", ATTRS{idVendor}=="0424", ATTRS{idProduct}=="2513", ENV{SYSTEMD_WANTS}="upgarmin.service"

the systemd service:

[Unit]
Description=Sync Garmin Device with Dropbox

[Service]
Type=oneshot
ExecStart=/home/wash/bin/garmin_upload.sh

[Install]
WantedBy=multi-user.target

But this does not seem to execute. If i start the service manually with systemctl start upgarmin.service it does work, though. I have enabled the systemd service. Why would this be?

Offline

#4 2015-11-12 03:40:06

pdizzle
Member
Registered: 2013-02-07
Posts: 15

Re: [Solved] Udev rule to rsync folders on connect fails

I updated my service file to directly follow the syntax as you had laid out and now it works:

[Unit]
Description=Sync Garmin Device with Dropbox
Requires=media-GARMIN.mount
After=media-GARMIN.mount


[Service]
Type=oneshot
ExecStart=/home/wash/bin/garmin_upload

[Install]
WantedBy=media-GARMIN.mount

thanks again for the help

Offline

#5 2015-11-12 05:03:27

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [Solved] Udev rule to rsync folders on connect fails

No  problem. Please remember to mark your thread as [Solved] by editing your first post and prepending it to the title.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB