I am trying to automate a quick and dirty backup of a headless system. (I feel it is relevant to note that I am running Busybox utilities so this is the mount tool I have at my disposal) I have made a udev rule to execute a script when my USB device is plugged in and it does trigger and execute the called script.
Currently the script just mounts the device but it fails to do so. If I run the script manually, there is no error.
I added the line exec >/home/user/udev.out 2>&1
to try to figure out why it is failing.
Script Contents:
#!/bin/sh
exec >/home/user/udev.out 2>&1
mount -t ntfs-3g /dev/sdb1 /mnt/backup
exit 0
I know I shouldn't use /dev/sdb1 in the script, and I do generate a symlink in the udev rule, but just for error checking I have hardcoded the device.
I have also tried adding a 3 second sleep before the mount command to be sure the device could be detected by the system before executing the mount command, to no avail.
Results of udev.out:
mount: mounting /dev/sdb1 on /mnt/backup failed: No such device
I know the device is there and it is listed by fdisk. If I call the script from shell, it runs successfully no problem.
Has anyone encountered anything similar before? I am not sure how to proceed.
edit: udev rule:
SUBSYSTEM=="block", ATTRS{serial}=="serialforusbdrive", SYMLINK+="kingston%n"
SUBSYSTEM=="usb", ATTRS{serial}=="serialforusbdrive", RUN+="/usr/local/bin/backup.sh"
edit:
Clarification:
udev rule triggers and runs my script.
The script when run manually from shell (I type /usr/local/bin/backup.sh
in shell and the drive is mounted)
The script when run by udev rule (RUN+="/usr/local/bin/backup.sh") runs the script but fails to mount the drive.
ntfs-3g
already loaded?ntfs-3g /dev/sdb1 /mnt/backup
instead ofmount /dev/sdb1 /mnt/backup
and it works like a charm!