I have a script set up to run when a certain usb drive is inserted. It is supposed to copy a folder from the usb drive into a backup folder, and write over this folder if it already exists. However, when I plug in my usb drive, it creates the folder but it doesn't copy any files.
My .rules looks like this:
ACTION=="add", ATTR{idVendor}==Vendor, ATTR{idProduct}==Product, RUN+="/bin/sh /path/to/file/mkBackup"
My file mkBackup looks like this:
#!/bin/bash
a="/path/to/file/Backup"
if [ -e $a ]; then
rm -rf $a
fi
mkdir $a
cp -r /path/to/usb/folder $a
When it is run by udev
, the Backup folder is created but it is empty, but when I just run ./mkBackup
, the folder is created and everything is copied. This is my first time using udev
to do something like this, so please forgive me if this seems like a simple question. Thank you in advance.