-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_instance_cookie_jars.sh
executable file
·54 lines (44 loc) · 1.23 KB
/
get_instance_cookie_jars.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
#!/bin/bash
CJAR_DIR=.
CJAR_TMP_FILENAME=cookie_jar.tmp
EXPECTED_INSTANCES=
MAXIMUM_RETRIES=10
ACTUAL_INSTANCES=0
TRIES=0
usage() { echo "Usage: $0 -e <expected number of instances> [-m <maximum number of tries - default 10>] [-d <cookie jar directory - default .>]" 1>&2; exit 1; }
while getopts ":e:m:d:" o; do
case "${o}" in
e)
EXPECTED_INSTANCES=${OPTARG}
;;
m)
MAXIMUM_RETRIES=${OPTARG}
;;
d)
CJAR_DIR=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${EXPECTED_INSTANCES}" ]; then
usage
fi
while [ $TRIES -lt $MAXIMUM_RETRIES -a $ACTUAL_INSTANCES -lt $EXPECTED_INSTANCES ]
do
TRIES=$[$TRIES+1]
curl -s -X POST dora.sunset.cf-app.com/session -c $CJAR_TMP_FILENAME > /dev/null || exit $?
instance=`grep JSESSIONID cookie_jar.tmp | cut -f7`
echo "instance >>$instance<<"
CJAR=${CJAR_DIR}/cookie_jar_$instance.cjar
if [ -f $CJAR ]; then
echo "cookie jar for $instance already exists"
rm $CJAR_TMP_FILENAME
else
mv $CJAR_TMP_FILENAME $CJAR
ACTUAL_INSTANCES=$[$ACTUAL_INSTANCES+1]
fi
done
echo "found $ACTUAL_INSTANCES in $TRIES tries"