chimie4psmn / submit / clean_up.sh @ 17
Historique | Voir | Annoter | Télécharger (737 octet)
1 | 16 | tjiang | #!/bin/bash |
---|---|---|---|
2 | 17 | ltaulell | # $Id$ |
3 | 16 | tjiang | #How to use this script: |
4 | 16 | tjiang | #The usage is similar to the command rsync, |
5 | 16 | tjiang | #clean_up files_to_be_synced destination |
6 | 17 | ltaulell | set -eu # partial strict mode |
7 | 17 | ltaulell | set -o pipefail # exit, with error msg from any forked subshell, if exit code != 0 |
8 | 17 | ltaulell | set -x # Trace each command, can be commented out |
9 | 16 | tjiang | |
10 | 16 | tjiang | #number of files to be synced |
11 | 16 | tjiang | narg=$(($#-1)) |
12 | 16 | tjiang | |
13 | 16 | tjiang | #files to be synced |
14 | 16 | tjiang | files=${@:1:$narg} |
15 | 16 | tjiang | |
16 | 16 | tjiang | pwd=$(pwd) |
17 | 16 | tjiang | #echo "${files}" |
18 | 17 | ltaulell | # TODO: enter a loop, and sync one file at a time (Tao said) |
19 | 16 | tjiang | rsync -r -c $@ |
20 | 16 | tjiang | |
21 | 17 | ltaulell | |
22 | 16 | tjiang | #If exit code is 0 (succeed), then delete the files |
23 | 16 | tjiang | if [[ $? -ne 0 ]] |
24 | 16 | tjiang | then |
25 | 16 | tjiang | echo "Failed copying back all the data. Please verify manually." |
26 | 16 | tjiang | echo "The directory is: ${pwd}" |
27 | 16 | tjiang | exit 1 |
28 | 16 | tjiang | else |
29 | 17 | ltaulell | echo "deleting ${files}" |
30 | 16 | tjiang | rm $files |
31 | 16 | tjiang | echo "Done" |
32 | 16 | tjiang | fi |