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 | # ========= |
---|
11 | function get_gencmip6 { |
---|
12 | ccc_myproject | sed -e'1,/gencmip6/d' | grep -m 1 $1 |
---|
13 | } |
---|
14 | |
---|
15 | function get_gencmip6_login { |
---|
16 | ccc_myproject | sed -n -e'/gencmip6/,/^$/p' | head -n -1 | tail -n +3 |
---|
17 | } |
---|
18 | |
---|
19 | |
---|
20 | # Default values |
---|
21 | # ============== |
---|
22 | fg_dry=false |
---|
23 | fg_verbose=false |
---|
24 | |
---|
25 | fg_all=true |
---|
26 | fg_login=true |
---|
27 | fg_bilan=true |
---|
28 | fg_store=true |
---|
29 | |
---|
30 | # Get arguments from command line |
---|
31 | # =============================== |
---|
32 | while getopts :hdaltsv Opt ; do |
---|
33 | case $Opt in |
---|
34 | h) |
---|
35 | echo "usage: $0 [-h]Â [-a] [-l] [-b] [-s] [-d] [-v]" |
---|
36 | echo "" |
---|
37 | echo "options :" |
---|
38 | echo " -h : print this help and exit" |
---|
39 | echo " -d : dry run, no file produced" |
---|
40 | echo " -a : produce all files (default)" |
---|
41 | echo " -l : produce login file" |
---|
42 | echo " -b : produce bilan file" |
---|
43 | echo " -s : produce store file" |
---|
44 | echo " -v : verbose" |
---|
45 | exit 0 ;; |
---|
46 | d) |
---|
47 | fg_dry=true |
---|
48 | ;; |
---|
49 | a) |
---|
50 | fg_all=true |
---|
51 | ;; |
---|
52 | l) |
---|
53 | fg_login=true |
---|
54 | fg_all=false |
---|
55 | fg_bilan=false |
---|
56 | fg_store=false |
---|
57 | ;; |
---|
58 | t) |
---|
59 | fg_bilan=true |
---|
60 | fg_all=false |
---|
61 | fg_login=false |
---|
62 | fg_store=false |
---|
63 | ;; |
---|
64 | s) |
---|
65 | fg_store=true |
---|
66 | fg_all=false |
---|
67 | fg_login=false |
---|
68 | fg_bilan=false |
---|
69 | ;; |
---|
70 | v) |
---|
71 | fg_verbose=true |
---|
72 | ;; |
---|
73 | :) |
---|
74 | echo "$0: -"${OPTARG}" option: missing value" |
---|
75 | exit 1 |
---|
76 | ;; |
---|
77 | \?) |
---|
78 | echo "$0: -"${OPTARG}" option: not supported" |
---|
79 | exit 1 |
---|
80 | ;; |
---|
81 | esac |
---|
82 | done |
---|
83 | shift $(($OPTIND-1)) |
---|
84 | |
---|
85 | |
---|
86 | # Files and directories |
---|
87 | # ===================== |
---|
88 | LOCAL_DIR="/ccc/cont003/home/dsm/p86ipsl/CCC_MYPROJECT/output" |
---|
89 | SAVE_DIR="/ccc/work/cont003/dsm/p86ipsl/CCC_MYPROJECT/" |
---|
90 | |
---|
91 | if ( ${fg_dry} ) ; then |
---|
92 | OUT_LOGIN="/dev/stdout" |
---|
93 | OUT_BILAN="/dev/stdout" |
---|
94 | OUT_STORE="/dev/stdout" |
---|
95 | else |
---|
96 | OUT_LOGIN="OUT_CONSO_LOGIN" |
---|
97 | OUT_BILAN="OUT_CONSO_BILAN" |
---|
98 | OUT_STORE="OUT_CONSO_STORE" |
---|
99 | fi |
---|
100 | |
---|
101 | #Today=$( date +%F ) |
---|
102 | Today=$( ccc_myproject | grep gencmip6 | gawk '{print $NF}' ) |
---|
103 | |
---|
104 | |
---|
105 | # Produce files |
---|
106 | # ============= |
---|
107 | |
---|
108 | cd ${LOCAL_DIR} |
---|
109 | |
---|
110 | # 1- Conso par login (HOME) |
---|
111 | # ------------------------- |
---|
112 | # on garde la trace de chaque login, date en tete, en remplacant le |
---|
113 | #Â fichier a chaque fois : OUT_CONSO_LOGIN |
---|
114 | if ( ${fg_all} || ${fg_login} ) ; then |
---|
115 | get_gencmip6_login | \ |
---|
116 | gawk -v Today=$Today '{printf "%10s %-10s %10.2f hours\n", Today, $1, $2}' \ |
---|
117 | > ${OUT_LOGIN} |
---|
118 | fi |
---|
119 | |
---|
120 | # 2- Conso total par jour |
---|
121 | # ----------------------- |
---|
122 | # on garde le total, date en tete en accumulant dans le fichier : |
---|
123 | #Â OUT_CONSO_BILAN |
---|
124 | if ( ${fg_all} || ${fg_bilan} ) ; then |
---|
125 | printf "%10s " ${Today} >> ${OUT_BILAN} |
---|
126 | get_gencmip6 Total | \ |
---|
127 | gawk '{printf " %s %10.2f hours ", "total", $2}' \ |
---|
128 | >> ${OUT_BILAN} |
---|
129 | get_gencmip6 Allocated | \ |
---|
130 | gawk '{printf " %s %10.2f hours ", "alloc", $2}' \ |
---|
131 | >> ${OUT_BILAN} |
---|
132 | get_gencmip6 Suggested | \ |
---|
133 | gawk '{printf " %s %7s ", "use_theo", $NF}' \ |
---|
134 | >> ${OUT_BILAN} |
---|
135 | get_gencmip6 Real | \ |
---|
136 | gawk '{printf " %s %7s ", "use_real", $NF}' \ |
---|
137 | >> ${OUT_BILAN} |
---|
138 | printf "\n" >> ${OUT_BILAN} |
---|
139 | fi |
---|
140 | |
---|
141 | # 3- volume cree sur STORE |
---|
142 | # ------------------------ |
---|
143 | # par login qui a consomme, en remplacant le fichier a chaque fois : |
---|
144 | #Â OUT_CONSO_STORE |
---|
145 | if ( ${fg_all} || ${fg_store} ) ; then |
---|
146 | for login in $( get_gencmip6_login | \ |
---|
147 | gawk '{if ($NF != 0.00) print $1}' ) ; do |
---|
148 | printf "%10s %-10s %6s %s\n" \ |
---|
149 | ${Today} ${login} \ |
---|
150 | $( du -sbh $(ccc_home -A -u ${login})/IGCM_OUT/IPSLCM6 ) |
---|
151 | done > ${OUT_STORE} |
---|
152 | fi |
---|
153 | |
---|
154 | |
---|
155 | # Save files (WORK) |
---|
156 | # ================= |
---|
157 | if ( ! ${fg_dry} ) ; then |
---|
158 | Suffix=$( echo ${Today} | sed 's/-//g' ) |
---|
159 | cp ${OUT_LOGIN} ${SAVE_DIR}/${OUT_LOGIN}_${Suffix} |
---|
160 | cp ${OUT_BILAN} ${SAVE_DIR}/${OUT_BILAN}_${Suffix} |
---|
161 | cp ${OUT_STORE} ${SAVE_DIR}/${OUT_STORE}_${Suffix} |
---|
162 | fi |
---|
163 | |
---|