2

I want to execute rsync command which syncs my local directory with the external ssd. I followed the instructions given in this link. to execute some command based on udev rules. This shows how to run the command for specific usb drive based on idVendor and idProduct. Here is the command I have in my /etc/udev/rules.d/test.rules:

ATTRS{idVendor}=="0781", ATTRS{idProduct}=="558c", RUN+="/temp/auto_back.sh"

and in /tmp/auto_back.sh I just have

#!/bin/bash

# auto backup command 

rsync -avzh /home/abhishek/Dropbox /media/abhishek/Hachiko

I don't have much insight about this. I just thought it might work. But it doesn't. I read that sometimes the command gets executed before the drive is even mounted. Can you give me some insight on what I am doing wrong, and how this thing works? Also, is there any way to make the command in script to wait for some time before it executes?

2 Answers 2

1

Udev will work only if you pass correct information like below for usb,

KERNEL=="sd*", ATTRS{vendor}=="<Vendor name>", ATTRS{model}=="<Model>", ATTRS{serial}=="<serial>", RUN+="/your script path"

Alternatively,

I could not write complete code since not sure kind of hardware and other details, however check this logic and put in crontab either use long running process or keep on checking your logs. New hardware should be visible in dmesg output.

if "string matching in dmesg" && "within 30s"; then 
     check disk is properly mounted
     check disk is writable
     start backup
fi

Put check logic for disk is writable and properly mounted before starting backup.

1
  • Thanks. I will try crontab. But can you check that the idea I am trying is valid or not? May 28, 2019 at 13:18
0

you could add a wait for the disk to mount

eg:

while ! [ -w /media/abhishek/Hachiko ]
do sleep 1
done

but that requires that you are logged into the GUI when you plug the drive in it's probably better to over-ride the automount and mount the drive explicitly.

2
  • What do you mean by 'logged into the GUI'? I'm using mint 19. That means I am using GUI, right? May 28, 2019 at 13:14
  • you are after you log in.
    – Jasen
    May 29, 2019 at 1:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .