Updates
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / sim / spyFile.sh
CommitLineData
ee275c29 1#!/bin/bash
2
3pid=
4file=
5out=
6tee=0
7twait=30
8
9
10# --- Call on errors -------------------------------------------------
11error()
12{
13 echo "$@" > /dev/stderr
14 exit 1
15}
16
17# --- Help -----------------------------------------------------------
18usage()
19{
20 cat <<EOF
21Usage: $0 -p PID -f FILE [OPTIONS]
22
23Options:
24 -p,--pid PID Process identifier
25 -f,--file FILENAME File to monitor
26 -o,--out NAME Name of stored file
27 -w,--wait SECONDDS How many seconds to wait
28 -P,--pipe Use a tee when writing to file
29 -h,--help This help
30
31Output file is PID_NAME.log. If NAME is not specified it defaults to
32the base name of FILENAME minus possible ending .log.
33
34EOF
35}
36
37# --- Process command line -------------------------------------------
38while test $# -gt 0 ; do
39 case $1 in
40 -p|--pid) pid=$2 ; shift ;;
41 -f|--file) file=$2 ; shift ;;
42 -o|--out) out=$2 ; shift ;;
43 -w|--wait) twait=$2 ; shift ;;
44 -P|--pipe) tee=1 ;;
45 -h|--help) usage ; exit 0 ;;
46 *) error "Unknown option: $1" ;;
47 esac
48 shift
49done
50
51# --- Check settings -------------------------------------------------
52if test "X$pid" = "X" ; then error "No PID specified" ; fi
53if test "X$file" = "X" ; then error "No file specified" ; fi
54if test "X$out" = "X" ; then
55 out=`basename $file .log`
56fi
57
58# --- Make derived variables -----------------------------------------
59tmp=${pid}_${out}.tmp
60log=${pid}_${out}.log
61
62# --- Check grid authenticity ----------------------------------------
63if test ! -f /tmp/gclient_env_${UID} ; then
64 error "No AliEn environment file"
65fi
66. /tmp/gclient_env_${UID}
67alien-token-info | grep -q "Token is still valid"
68if test $? -ne 0 ; then
69 echo "Token not valid, please re-new" > /dev/stderr
70 exit 1
71fi
72
73
74# --- Main loop (eternal) --------------------------------------------
75while true ; do
76 if test $tee -gt 0 ; then
77 echo "=== Executing alien_spy $pid $file | tee $tmp ..."
78 alien_spy $pid $file | tee $tmp
79 else
80 echo "=== Executing alien_spy $pid $file > $tmp ..."
81 alien_spy $pid $file > $tmp
82 fi
83 l1=`stat -c %s $tmp`
421f877c 84 l2=0
85 if test -f $log ; then
86 l2=`stat -c %s $log`
87 fi
ee275c29 88 if test $l1 -ge $l2 ; then
89 mv $tmp $log
90 else
91 echo "New download smaller than old - exiting"
92 break
93 fi
94 sleep $twait
95done
96
97
98#
99# EOF
100#