I'm having trouble using udev to run a shell script that backs up my hard drives to an external drive whenever the external drive is connected via USB. Everything works except the actual call to rdiff-backup. The udev detects the hard drive and calls the script properly. The script runs and displays the desktop notifications properly, but rdiff-backup is never run by the shell script and the script runs to end immediately without ever backing up the drives. I've already edited my sudoers file so that the script has appropriate permissions.
I am aware that Cuttlefish would allow my to perform this action relatively easily, but in the interest of educating myself on the general method, I'd much prefer to learn to use the tools already built in to Linux to accomplish this on my own. Any help would be greatly appreciated.
My udev rules is defined as:
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1f75", ATTR{idProduct}="0621", RUN+="/home/nam/.scripts/backup_root_and_home_folders_to_external_drive.sh"
and my shell script is as follows:
#!/bin/bash
#sudo su
export DISPLAY=:0
export XAUTHORITY=/home/nam/.Xauthority
logger "Backing up root and home directories to external drive..."
###BACKUP ROOT DIRECTORY
#Issue system notification for backup begin
sv=$(date "+%T")
msgvar="Backing up directory / to external drive started at "
notif=${msgvar}${sv}
sudo -u nam DISPLAY=":0.0" notify-send -t 1000 "$notif"
#notify-send -t 1000 "$notif"
logger "$notif"
#sleep 5
#Start backup of / directory
st=$SECONDS
#sudo rdiff-backup -v6 --force --exclude /sys --exclude /run --exclude /media --exclude /proc --exclude /home / /media/nam/BACKUP1/root
sudo su
/usr/bin/rdiff-backup -v6 --exclude /sys --exclude /run --exclude /media --exclude /proc --exclude /home / /media/nam/BACKUP1/root
#logger "$ok"
#Issue system notification for backup end
sv=$(date "+%T")
stt=$SECONDS
et=$(($stt - $st))
#notify-send -t 1000 "Backup of directory / completed at $sv.
#Process took $et seconds."
sudo -u nam DISPLAY=":0.0" notify-send -t 1000 "Backup of directory / completed at $sv.
Process took $et seconds."
###BACKUP HOME DIRECTORY
#Issue system notification for backup begin
sv=$(date "+%T")
msgvar="Backing up directory /home to external drive started at "
notif=${msgvar}${sv}
#notify-send -t 1000 "$notif"
sudo -u nam DISPLAY=":0.0" notify-send -t 1000 "$notif"
#Start backup of /home directory
#sudo rdiff-backup -v6 --force /home/ /media/nam/BACKUP1/home/
sudo su
sudo /usr/bin/rdiff-backup -v6 /home/ /media/nam/BACKUP1/home/
#Issue system notification for backup end
sv=$(date "+%T")
stt=$SECONDS
et=$(($stt - $st))
#notify-send -t 1000 "Backup of directory /home completed at $sv.
#Process took $et seconds."
sudo -u nam DISPLAY=":0.0" notify-send -t 1000 "Backup of directory /home completed at $sv.
Process took $et seconds."
man udev
, "==" compares for equality and "=" assigns a value to a key. – Lingnik Mar 28 '17 at 04:10