Last active
December 17, 2015 18:18
-
-
Save mhluska/5651803 to your computer and use it in GitHub Desktop.
Used with udev to sync a backup drive.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
drive_name="${1}" | |
if [ -z "${drive_name}" ]; then | |
exit 1 | |
fi | |
USERNAME='username' | |
SOURCE_DIR="/home/${USERNAME}/Backup" | |
function notify() { | |
su "${USERNAME}" -c "DISPLAY=:0.0 /usr/bin/notify-send '${1}'" | |
} | |
# Wait for Ubuntu to auto-mount the drive. | |
drive_dir= | |
while [ -z "${drive_dir}" ]; do | |
sleep 2 | |
drive_dir="$(grep "${drive_name}" /etc/mtab | awk '{print $2}')" | |
done | |
notify "Syncing ${drive_dir}" | |
HOME=/root unison "${SOURCE_DIR}" "${drive_dir}" -batch -prefer newer -times=true -perms 0 | |
notify "Finished syncing ${drive_dir}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment