-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploadLarge2NCI.sge
56 lines (45 loc) · 1.5 KB
/
uploadLarge2NCI.sge
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
#!/bin/bash
# SGE OPTIONS
#$ -V
#$ -cwd
#$ -b n
#$ -l mem_requested=8G,fast_dm=10
#$ -q short.q
#$ -S /bin/bash
#$ -N transfer_large
#$ -M [email protected]
#$ -m ae
# INPUT DIRECTORIES
# So for the command... qsub TransferLarge2NCI.sge /path/to/filename.tar.gz /path/on/nci/to/move/to
FILEPATH=$1
NCI_DIR=$2
# Remember to change this and the email once you start using it.
## CLEAN UP NCI_DIR so it does not end with a forward slash
[[ "${NCI_DIR}" == */ ]] && NCI_DIR="${NCI_DIR: : -1}"
# Check if the input variable is actually a directory
# 1. Go to parent directory of the directory we are backing up
# 2. Create an MD5 file of the TAR file
# 3. Transfer to NCI
# 4. Run remote checksum to ensure it is fine
# Get paths from input directory
PARENT_DIR="$(dirname "$FILEPATH")"
FILENAME="$(basename "$FILEPATH")"
MD5_FILE=${FILENAME}.md5
# Navigate to parent directory
cd $PARENT_DIR
# If checksum not present, create one
# Run checksum before transfer to ensure it is fine
if [[ ! -f "$MD5_FILE" ]]
then
md5sum $FILENAME > $MD5_FILE
md5sum -c $MD5_FILE
fi
## Create directory on NCI if it doesn't exist
ssh ${LOGIN} "mkdir -p ${NCI_DIR}"
# Transfer to NCI
# If you are using my script, remember to change to your username and ensure your SSH keys are properly set
rsync -az ${FILENAME} ${LOGIN}:${NCI_DIR}/${FILENAME}
rsync -az ${MD5_FILE} ${LOGIN}:${NCI_DIR}/${MD5_FILE}
# Run SSH remotely to check the transfer went fine.
ssh ${LOGIN} "cd ${NCI_DIR}; md5sum -c ${MD5_FILE}"