-
Notifications
You must be signed in to change notification settings - Fork 0
/
emerald2sdsc.sh
47 lines (35 loc) · 1.31 KB
/
emerald2sdsc.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
#!/bin/bash
start_time="$(date -u +%s)"
# --------------------------
# - file transfer settings
# --------------------------
logfile=screen.txt
[email protected]:/nfs/home/erfan/airflow/logs/*.logs
dest=/oasis/projects/nsf/ddp340/erfan/rsync_test/
while [ 1 ]
do
rsync -avz --partial $source $dest --log-file="$logfile"
if [ "$?" = "0" ] ; then
echo "rsync completed successfully!"
break
else
echo "Rsync failure. Backing off and retrying..."
sleep 180
fi
done
end_time="$(date -u +%s)"
secs="$(($end_time-$start_time))"
# ------------------
# - email settings
# ------------------
subject="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+="\n\nSent by Erfan's automated script on GitHub :)"
echo -e "$body" | mailx -s "$subject" -a "$logfile" "[email protected]"
# - usage:
# bash <(wget --no-cache -qO- https://github.com/cosmicshear/BlendSim/raw/master/nersc2sdsc.sh)
# - 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