]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/sim/spyFile.sh
Various updates for the production scripts
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / sim / spyFile.sh
1 #!/bin/bash
2
3 pid=
4 file=
5 out=
6 tee=0
7 twait=30
8
9
10 # --- Call on errors -------------------------------------------------
11 error()
12 {
13     echo "$@" > /dev/stderr 
14     exit 1
15 }
16
17 # --- Help -----------------------------------------------------------
18 usage() 
19 {
20     cat <<EOF
21 Usage: $0 -p PID -f FILE [OPTIONS]
22
23 Options:
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
31 Output file is PID_NAME.log.  If NAME is not specified it defaults to
32 the base name of FILENAME minus possible ending .log. 
33
34 EOF
35
36
37 # --- Process command line ------------------------------------------- 
38 while 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
49 done
50
51 # --- Check settings -------------------------------------------------
52 if test "X$pid"  = "X" ; then error "No PID specified" ; fi
53 if test "X$file" = "X" ; then error "No file specified" ; fi
54 if test "X$out"  = "X" ; then 
55     out=`basename $file .log` 
56 fi
57             
58 # --- Make derived variables -----------------------------------------
59 tmp=${pid}_${out}.tmp 
60 log=${pid}_${out}.log
61
62 # --- Check grid authenticity ----------------------------------------
63 if test ! -f /tmp/gclient_env_${UID} ; then 
64     error "No AliEn environment file"
65 fi
66 . /tmp/gclient_env_${UID}
67 alien-token-info | grep -q "Token is still valid"
68 if test $? -ne 0 ; then 
69     echo "Token not valid, please re-new" > /dev/stderr 
70     exit 1
71 fi
72
73
74 # --- Main loop (eternal) --------------------------------------------
75 while 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`
84     l2=`stat -c %s $log` 
85     if test $l1 -ge $l2 ; then 
86         mv $tmp $log
87     else 
88         echo "New download smaller than old - exiting"
89         break 
90     fi 
91     sleep $twait
92 done
93
94
95 #
96 # EOF
97 #