-
Notifications
You must be signed in to change notification settings - Fork 0
/
nersc2sdsc.sh
61 lines (48 loc) · 2.09 KB
/
nersc2sdsc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
if [ -n "$STY" ]; then
echo "Please press CTRL+A+D to detach from this screen session while leaving it open in background."
fi
start_time="$(date -u +%s)"
# --------------------------
# - file transfer settings
# --------------------------
logfile="rsync-log.txt" # will be attached to the email
excludelist=/oasis/projects/nsf/ddp340/erfan/exclude-list.txt
delay=3 # minutes of delay between the attempts
[email protected]:/global/cscratch1/sd/tyson1/projects/blending/buzzard_v1.9.2_lsst/zsnb/zsnb.*.fit
dest=/oasis/projects/nsf/ddp340/tyson1/buzzard_v1.9.2_lsst_r3/
while [ 1 ]
do
rsync -avz --partial --exclude-from "$excludelist" "$source" "$dest" --log-file="$logfile" # -p will re-transfer the files from where it was left off
if [ "$?" = "0" ] ; then
echo "Rsync completed successfully!"
break
else
echo "Rsync failure. Backing off and retrying in $delay minutes ..."
sleep "$delay"m
fi
done
end_time="$(date -u +%s)"
secs="$(($end_time-$start_time))"
# ------------------
# - email settings
# ------------------
subject="[$$-$RANDOM] File transfer completed successfully"
body=''
body+="Hi Tony and Erfan,\n\n"
body+=$(printf "Congratulations! Your file transfer from NERSC to SDSC has completed successfully in %02d:%02d:%02d hms. " $(($secs/3600)) $(($secs%3600/60)) $(($secs%60)))
body+="Please have a look at the attached file $logfile."
body+="\n\nSent by Erfan's automated script on GitHub :)"
echo -e "$body" | mailx -s "$subject" -a "$logfile" "[email protected] [email protected]"
# -------------------------------
# - usage [screen is optional]:
# -------------------------------
# screen -S myscreen (to start)
# bash <(wget --no-cache -qO- https://github.com/cosmicshear/BlendSim/raw/master/nersc2sdsc.sh)
# CTRL + A + D (to detach)
# screen -X -S myscreen quit (to kill)
# -------------------------------
# - used ref:
# -------------------------------
# https://unix.stackexchange.com/questions/48298/can-rsync-resume-after-being-interrupted
# https://stackoverflow.com/questions/8260858/how-to-send-email-from-terminal