Skip to content

Instantly share code, notes, and snippets.

@hfs
Created January 18, 2015 14:05
Show Gist options
  • Save hfs/bfc505fe572f821b0474 to your computer and use it in GitHub Desktop.
Save hfs/bfc505fe572f821b0474 to your computer and use it in GitHub Desktop.
Run full backup with Dirvish, mount and unmount the external backup drive, and send status output to the desktop environment as notifications
#!/bin/sh
MOUNTPOINT=/mnt/backup
notify() {
returncode=$1
summary=$2
message=$3
if [ $returncode -gt 0 ]; then
urgency=critical
timeout=1000
else
urgency=low
timeout=10000
fi
notify-send --urgency=$urgency --expire-time=$timeout "$summary" "$message"
}
notify_live() {
summary=$1
while read line; do
accu="$line"
while read -t 1 more; do
accu=`echo -e "$accu\n$more"`
done
notify-send "$summary" "$accu"
done
}
output=$(gksudo -- mount --verbose $MOUNTPOINT 2>&1)
notify $? "Backup" "$output"
output=$(gksudo -- dirvish-runall | notify_live "dirvish" 2>&1)
df=$(df -h $MOUNTPOINT)
notify $? "Backup finished" "$df"
output=$(gksudo -- umount --verbose $MOUNTPOINT 2>&1)
notify $? "Backup" "$output"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment