source: TOOLS/ConsoGENCMIP6/bin/old/conso_gencmip6_v4 @ 4035

Last change on this file since 4035 was 2413, checked in by labetoulle, 9 years ago

Move all scripts to the same dir to use common configuration files

  • Property svn:executable set to *
File size: 4.6 KB
Line 
1#!/bin/bash
2#
3# cron pour garder trace de la compta et des volumes de fichiers crees
4# a executer chaque matin a 6h00
5# ======================================================================
6#. /etc/profile
7
8
9# Functions
10# =========
11function get_gencmip6 {
12  ccc_myproject | sed -e'1,/gencmip6/d' | grep -m 1 $1
13}
14
15function get_gencmip6_login {
16  ccc_myproject | sed -n -e'/gencmip6/,/^$/p' | head -n -1 | tail -n +3
17}
18
19
20# Default values
21# ==============
22fg_dry=false
23fg_verbose=false
24
25fg_all=true
26fg_param=true
27fg_login=true
28fg_bilan=true
29fg_store=true
30
31# Get arguments from command line
32# ===============================
33while getopts :hdaltsv Opt ; do
34  case $Opt in
35    h)
36      echo "usage: $0 [-h] [-a] [-l] [-b] [-s] [-d] [-v]"
37      echo ""
38      echo "options :"
39      echo "  -h : print this help and exit"
40      echo "  -d : dry run, no file produced"
41      echo "  -a : produce all files (default)"
42      echo "  -p : produce param file"
43      echo "  -l : produce login file"
44      echo "  -b : produce bilan file"
45      echo "  -s : produce store file"
46      echo "  -v : verbose"
47      exit 0 ;;
48    d)
49      fg_dry=true
50      ;;
51    a)
52      fg_all=true
53      ;;
54    l)
55      fg_login=true
56      fg_all=false
57      fg_param=false
58      fg_bilan=false
59      fg_store=false
60      ;;
61    t)
62      fg_bilan=true
63      fg_all=false
64      fg_param=false
65      fg_login=false
66      fg_store=false
67      ;;
68    s)
69      fg_store=true
70      fg_all=false
71      fg_param=false
72      fg_login=false
73      fg_bilan=false
74      ;;
75    p)
76      fg_param=true
77      fg_all=false
78      fg_login=false
79      fg_bilan=false
80      fg_store=false
81      ;;
82    v)
83      fg_verbose=true
84      ;;
85    :)
86      echo "$0: -"${OPTARG}" option: missing value"
87      exit 1
88      ;;
89    \?)
90      echo "$0: -"${OPTARG}" option: not supported"
91      exit 1
92      ;;
93  esac
94done
95shift $(($OPTIND-1))
96
97
98# Files and directories
99# =====================
100LOCAL_DIR="/ccc/cont003/home/dsm/p86ipsl/CCC_MYPROJECT/output"
101SAVE_DIR="/ccc/work/cont003/dsm/p86ipsl/CCC_MYPROJECT/"
102
103if ( ${fg_dry} ) ; then
104  OUT_PARAM="/dev/stdout"
105  OUT_LOGIN="/dev/stdout"
106  OUT_BILAN="/dev/stdout"
107  OUT_STORE="/dev/stdout"
108else
109  OUT_PARAM="OUT_CONSO_PARAM_v4"
110  OUT_LOGIN="OUT_CONSO_LOGIN_v4"
111  OUT_BILAN="OUT_CONSO_BILAN_v4"
112  OUT_STORE="OUT_CONSO_STORE_v4"
113fi
114
115#Today=$( date +%F )
116Today=$( ccc_myproject | grep gencmip6 | gawk '{print $NF}' )
117
118
119# Produce files
120# =============
121
122cd ${LOCAL_DIR}
123
124# 1- Parametres du projet
125# -----------------------
126echo "{" > ${OUT_PARAM}
127ccc_myproject | grep gencmip6 | \
128    gawk '{printf "  \"project\": \"%s\",\n", $4}' \
129    >> ${OUT_PARAM}
130get_gencmip6 deadline | \
131    gawk '{printf "  \"deadline\": \"%10s\",\n", $NF}' \
132    >> ${OUT_PARAM}
133get_gencmip6 Allocated | \
134    gawk '{printf "  \"alloc\": %10.2f,\n", $NF}' \
135    >> ${OUT_PARAM}
136echo "}" >> ${OUT_PARAM}
137
138# 2- Conso par login (HOME)
139# -------------------------
140# on garde la trace de chaque login, date en tete, en remplacant le
141# fichier a chaque fois : OUT_CONSO_LOGIN
142if ( ${fg_all} || ${fg_login} ) ; then
143  get_gencmip6_login | \
144      gawk -v Today=$Today '{printf "%10s %-10s %10.2f hours\n", Today, $1, $2}' \
145      > ${OUT_LOGIN}
146fi
147
148# 3- Conso total par jour
149# -----------------------
150# on garde le total, date en tete en accumulant dans le fichier :
151# OUT_CONSO_BILAN
152if ( ${fg_all} || ${fg_bilan} ) ; then
153  printf "%10s " ${Today} >> ${OUT_BILAN}
154  get_gencmip6 Total | \
155      gawk '{printf "    %s %10.2f hours ", "total", $2}' \
156      >> ${OUT_BILAN}
157  get_gencmip6 Allocated | \
158      gawk '{printf "    %s %10.2f hours ", "alloc", $2}' \
159      >> ${OUT_BILAN}
160  get_gencmip6 Suggested | \
161      gawk '{printf "    %s %7s ", "use_theo", $NF}' \
162      >> ${OUT_BILAN}
163  get_gencmip6 Real | \
164      gawk '{printf "    %s %7s ", "use_real", $NF}' \
165      >> ${OUT_BILAN}
166  printf "\n" >> ${OUT_BILAN}
167fi
168
169# 4- volume cree sur STORE
170# ------------------------
171# par login qui a consomme, en remplacant le fichier a chaque fois :
172# OUT_CONSO_STORE
173if ( ${fg_all} || ${fg_store} ) ; then
174  for login in $( get_gencmip6_login | \
175                  gawk '{if ($NF != 0.00) print $1}' ) ; do
176    for dirname in $( ls -d $(ccc_home -A -u ${login})/IGCM_OUT/* ) ; do
177      printf "%10s %-10s %6s %s\n" \
178             ${Today} ${login} \
179             $( du -sbh ${dirname} )
180    done
181  done > ${OUT_STORE}
182fi
183
184# Save files (WORK)
185# =================
186if ( ! ${fg_dry} ) ; then
187  Suffix=$( echo ${Today} | sed 's/-//g' )
188  cp ${OUT_PARAM} ${SAVE_DIR}/${OUT_PARAM}_${Suffix}
189  cp ${OUT_LOGIN} ${SAVE_DIR}/${OUT_LOGIN}_${Suffix}
190  cp ${OUT_BILAN} ${SAVE_DIR}/${OUT_BILAN}_${Suffix}
191  cp ${OUT_STORE} ${SAVE_DIR}/${OUT_STORE}_${Suffix}
192fi
193
Note: See TracBrowser for help on using the repository browser.