Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cat /root/bin/copy.home.dirs.sh
- #!/bin/bash -e
- # run bash with -e to exit on errors
- # create a function that we can attach a signal to
- # in case we want to stop this script
- # otherwise if we press Ctrl-C, it will just continue
- # with the next iteration in the loop
- cleanup ()
- {
- kill -s SIGTERM $!
- exit 0
- }
- # now set the trap
- trap cleanup SIGINT SIGTERM
- SOURCE=a.example.com
- LOGFILE=home.copy.log
- # we will use a prepared file 'users' whose contents are a list of users, one user per line
- while read USER
- do echo "Working on $USER" | tee -a $LOGFILE
- TIMING="$(time ( rsync -avSHPz root@$SOURCE:/home/$USER/ /nas_home/$USER/ ) 2>&1 1>/dev/null )"
- echo $TIMING | tee -a $LOGFILE
- echo "/home/$USER copied to new NAS" | tee -a $LOGFILE
- echo "" | tee -a $LOGFILE
- done < "users"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement