forked from MRCIEU/godmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_upload.sh
executable file
·106 lines (83 loc) · 2.31 KB
/
check_upload.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
set -e
source ./config
checkFirstArg () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
echo $"Error: $1 is not a valid section identifier"
echo $"Need to specify a value from 01 to $e"
echo $"Usage: $0 <pipeline section> {check|upload}"
exit 1
}
checkSecondArg () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
echo $"Error: $2 is not a valid action"
echo $"Specify either 'check' or 'upload'"
echo $"Usage: $0 <pipeline section> {check|upload}"
exit 1
}
source resources/logs/check_logs.sh
source resources/logs/check_results.sh
for i in {1..17}; do sections[$(($i-1))]=`printf "%02d" ${i}`; done
checkFirstArg "$1" "${sections[@]}"
actions=("check" "upload")
checkSecondArg "$2" "${actions[@]}"
echo ""
echo "Checking log files for $1"
eval "check_logs_$1"
echo ""
echo "Checking results for $1"
eval "check_results_$1"
echo ""
echo "Section $1 has been successfully completed!"
if [ "$2" = "upload" ]
then
echo ""
temp=`which sshpass 2>/dev/null | wc -l`
if [ ! "${temp}" = "0" ]
then
read -s -p "Enter SFTP password: " mypassword
export SSHPASS=${mypassword}
echo "Testing connection"
sshpass -e sftp -oBatchMode=no -b - ${sftp_username}@${sftp_address}:${sftp_path}/${sftp_username} << !
bye
!
echo "Connection established"
else
echo "sshpass is not installed."
echo "The results will now be archived, once that is done they will be uploaded to the server"
fi
echo ""
echo "Tarring results and log files"
if [ "${1}" = "17" ]
then
suff="tar"
flags="cf"
else
suff="tgz"
flags="czf"
fi
tar ${flags} results/${study_name}_${1}.${suff} config resources/parameters results/${1}
echo "Successfully created results archives"
echo "Generating md5 checksum"
md5sum results/${study_name}_${1}.${suff} > results/${study_name}_${1}.md5sum
echo ""
if [ ! "${temp}" = "0" ]
then
export SSHPASS=${mypassword}
sshpass -e sftp -oBatchMode=no -b - ${sftp_username}@${sftp_address}:${sftp_path}/${sftp_username} << !
dir
put results/${study_name}_${1}.md5sum
put results/${study_name}_$1.${suff}
bye
!
else
read -s -p "Ready to upload? Press enter to continue: " anykey
sftp ${sftp_username}@${sftp_address}:${sftp_path}/${sftp_username} <<EOF
dir
put results/${study_name}_${1}.md5sum
put results/${study_name}_$1.${suff}
EOF
fi
fi