forked from parallelworks/interactive_session
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstream.sh
More file actions
executable file
·59 lines (51 loc) · 1.45 KB
/
stream.sh
File metadata and controls
executable file
·59 lines (51 loc) · 1.45 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
#!/bin/bash
# Runs on the remote host
# Inputs:
# --host localhost
# --pushpath pw/path/to/filename
# --pushfile filename
# --delay 30
# --port ${PARSL_CLIENT_SSH_PORT}
# --masterIP internal-IP-of-controller-node
# Exports inputs in the formart
# --a 1 --b 2 --c 3
# to:
# export a=1 b=2 c=3
parseArgs() {
index=1
args=""
for arg in $@; do
prefix=$(echo "${arg}" | cut -c1-2)
if [[ ${prefix} == '--' ]]; then
pname=$(echo $@ | cut -d ' ' -f${index} | sed 's/--//g')
pval=$(echo $@ | cut -d ' ' -f$((index + 1)))
# To support empty inputs (--a 1 --b --c 3)
if [ ${pval:0:2} != "--" ]; then
echo "export ${pname}=${pval}" >> $(dirname $0)/stream-env.sh
export "${pname}=${pval}"
fi
fi
index=$((index+1))
done
}
parseArgs $@
if [ -z "${port}" ]; then
port_flag=""
else
port_flag=" -p ${port} "
fi
sshcmd="ssh ${resource_ssh_usercontainer_options} ${port_flag} $host"
#pushpath=$(ls ${pushpath}*)
${sshcmd} 'cat >>"'$pushpath'"' >> logstream.out 2>&1
while true; do
if [ -f "$pushfile" ]; then
echo "Running" >> logstream.out 2>&1
tail -c +1 -f "$pushfile" | ${sshcmd} 'cat >>"'$pushpath'"' >> logstream.out 2>&1
echo CLOSING PID: $? >> logstream.out 2>&1
exit 0
else
echo "Preparing" >> logstream.out 2>&1
echo "preparing inputs" | ${sshcmd} 'cat >>"'$pushpath'"' >> logstream.out 2>&1
sleep $delay
fi
done