Last active
January 15, 2017 20:32
-
-
Save senorsmile/601479c68d9ab1c7518b0a8106db4ea3 to your computer and use it in GitHub Desktop.
add message if rsync already running
This file contains hidden or 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
| #!/usr/bin/env bash | |
| #-------- | |
| # ALL dirs must end with a backslash | |
| #-------- | |
| now=$(date +%Y-%m-%d_%H:%M:%S_%N) | |
| src='/home/shaun/' | |
| dest_url='127.0.0.1' | |
| dest_dir='/home/shaun/rsync_backups/' | |
| dest_username='shaun' | |
| src_dirs=( | |
| Downloads/ | |
| Desktop/ | |
| ) | |
| [[ $(ps aux | grep [r]sync) ]] && { | |
| echo "rsync already running. Exiting..." | |
| } || { #only run if rsync process not already running | |
| for dir in "${src_dirs[@]}"; do | |
| /usr/bin/rsync -avzP "${src}${dir}" "${dest_username}@${dest_url}:${dest_dir}" &>"/var/log/backups_${now}" | |
| done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment