Jpp  debug
the software that should make you happy
JCookie.sh
Go to the documentation of this file.
1 #!/bin/zsh
2 #
3 # \author mdejong
4 #
5 script=${0##*/}
6 
7 if [ -z $JPP_DIR ]; then
8  echo "Variable JPP_DIR undefined."
9  exit
10 fi
11 
12 source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
13 
14 set_variable COOKIE `getCookie`
15 set_variable TIMEOUT_S 20
16 
17 if do_usage $*; then
18  usage "$script"\
19  "\nUtility script to check database cookie file."\
20  "\nIf needed, the user is prompted to create new cookie file."
21 fi
22 
23 # test cookie
24 
25 if [[ -f $COOKIE ]]; then
26 
27  JPrintDB -C $COOKIE -q detector >& /dev/null
28 
29  if (( $? != 0 )); then
30  echo "Remove broken cookie file $COOKIE";
31  rm -f $COOKIE
32  fi
33 fi
34 
35 if [[ ! -f $COOKIE ]]; then
36 
37  if [[ -z "$DBCOOKIE" ]]; then
38 
39  echo "Enter input within $TIMEOUT_S seconds."
40  echo -n "User name: "
41  read -t $TIMEOUT_S USR
42  if (( $? != 0 )); then
43  fatal "Timeout at user input."
44  fi
45  echo -n "Password: "
46  read -t $TIMEOUT_S -s PWD
47  echo
48  if (( $? != 0 )); then
49  fatal "Timeout at user input."
50  fi
51 
52  set_variable SERVER `JServerDB`
53 
54  wget --no-check-certificate -q \
55  "https://${SERVER}/home.htm?usr=${USR}&pwd=${PWD}&persist=y&freenetbits=16" \
56  -O $COOKIE && sed -i -- "s/sid=/.in2p3.fr\\tTRUE\\t\/\\tTRUE\\t0\\tsid\\t/g" $COOKIE
57 
58  if [[ ! -f $COOKIE ]]; then
59  fatal "No cookie $COOKIE"
60  fi
61  else
62 
63  echo "Using DBCOOKIE; unset to disable."
64  fi
65 fi
66 
67 JPrintDB -C $COOKIE -q detector >& /dev/null
68 
69 CHECK_EXIT_CODE