-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·154 lines (123 loc) · 3.78 KB
/
run.sh
File metadata and controls
executable file
·154 lines (123 loc) · 3.78 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/sh
CONDOR_CHIRP=`condor_config_val LIBEXEC`/condor_chirp
MD5SUM=/usr/bin/md5sum
get_job_attr_blocking() {
#echo "Waiting for attribute $1" 1>&2
while /bin/true
do
Value=`$CONDOR_CHIRP get_job_attr $1`
if [ $? -ne 0 ]; then
echo "Chirp is broken!" 1>&2
return 1
fi
if [ "$Value" != "UNDEFINED" ]; then
echo "$Value" | tr -d '"'
return 0
fi
sleep 2
done
}
checksum() {
$MD5SUM $1 | awk '{print $1}'
}
receive_server() {
echo "I'm the server receiver"
# Start netcat listening on an ephemeral port (0 means kernels picks port)
# It will wait for a connection, then write that data to output_file
nc -d -l 0 > "$DESTINATION" &
# pid of the nc running in the background
NCPID=$!
# Sleep a bit to ensure nc is running
sleep 2
# parse the actual port selected from netstat output
NCPORT=`
netstat -t -a -p 2>/dev/null |
grep " $NCPID/nc" |
awk -F: '{print $2}' | awk '{print $1}'`
echo "Listening on $HOSTNAME $NCPORT"
$CONDOR_CHIRP set_job_attr JobServerAddress \"${HOSTNAME}\ ${NCPORT}\"
# Do other server things here...
#sleep 60
EXPECTED_CHECKSUM=`get_job_attr_blocking FileChecksum`
if [ $? -ne 0 ]; then
echo "Chirp is broken"
return 1
fi
while /bin/kill -0 $NCPID >/dev/null 2>&1
do
ls -l $DESTINATION
sleep 1
done
CHECKSUM=`checksum $DESTINATION`
if [ "$EXPECTED_CHECKSUM" != "$CHECKSUM" ]; then
echo "File did not arrive intact! Sender claimed checksum is $EXPECTED_CHECKSUM, but I calculated $CHECKSUM";
return 1
fi;
echo "$EXPECTED_CHECKSUM==$CHECKSUM";
$CONDOR_CHIRP set_job_attr ResultFileReceived TRUE
return 0
}
send_client() {
echo "I'm the client/sender"
JobServerAddress=`get_job_attr_blocking JobServerAddress`
if [ $? -ne 0 ]; then
echo "Chirp is broken"
return 1
fi
echo "JobServerAddress: $JobServerAddress";
host=`echo $JobServerAddress | awk '{print $1}'`
port=`echo $JobServerAddress | awk '{print $2}'`
CHECKSUM=`checksum $FILE_TO_SEND`
echo "Checksum: $CHECKSUM"
echo "Sending to $host $port"
echo "nc $host $port < $FILE_TO_SEND"
ls -l $FILE_TO_SEND
TIME_START=`date +%s`
nc $host $port < $FILE_TO_SEND
echo "Sent $?"
TIME_END=`date +%s`
$CONDOR_CHIRP set_job_attr ResultTimeStart "$TIME_START"
$CONDOR_CHIRP set_job_attr ResultTimeEnd "$TIME_END"
echo "Posting that transfer is done, checksum is $CHECKSUM"
$CONDOR_CHIRP set_job_attr FileChecksum "\"$CHECKSUM\""
return 0
}
SENDER="$1"
FILE_TO_SEND="$2"
RECEIVER="$3"
DESTINATION="$4"
if [ "$DESTINATION" = "" ]; then
cat <<END
Usage: $0 source_host source_file destination_host destination_file
END
exit 1
fi
HOSTNAME=`hostname`
echo "I am $HOSTNAME, node $_CONDOR_PROCNO"
echo "$SENDER $FILE_TO_SEND -> $RECEIVER $DESTINATION"
if [ "$RECEIVER" = "$HOSTNAME" ]; then
$CONDOR_CHIRP set_job_attr ResultsFileSent "\"$FILE_TO_SEND\""
$CONDOR_CHIRP set_job_attr ResultsHostSend "\"$SENDER\""
$CONDOR_CHIRP set_job_attr ResultsHostReceive "\"$RECEIVER\""
receive_server
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "Error receiving file"
fi
elif [ "$SENDER" = "$HOSTNAME" ]; then
send_client
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "Error sending file"
fi
else
echo "This node was not expected. Exiting immediately"
fi;
if [[ $_CONDOR_PROCNO = "0" ]]; then
echo "Waiting for partner"
get_job_attr_blocking Node1Done > /dev/null
# Give other node a bit of time to clear out after exiting.
sleep 5
elif [[ $_CONDOR_PROCNO = "1" ]]; then
$CONDOR_CHIRP set_job_attr Node1Done TRUE
fi