From 80f1253005b5f6c60b2596b910065829f3bdbdad Mon Sep 17 00:00:00 2001 From: Doug Le Tough Date: Tue, 25 Jul 2017 13:23:39 +0200 Subject: [PATCH] "test sys_refresh_ref_cron.sh" --- bin/sys_refresh_ref_cron.sh | 48 +++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/bin/sys_refresh_ref_cron.sh b/bin/sys_refresh_ref_cron.sh index 7349a2c..4b919da 100755 --- a/bin/sys_refresh_ref_cron.sh +++ b/bin/sys_refresh_ref_cron.sh @@ -23,6 +23,7 @@ # Ce script n'accepte *aucune* option # # @OPT: f:force:force:1/1:false::: +# @OPT: f:show-only:show-only:1/1:false::: # #------------------------------------------------------------------------------------------------------------------ # Liste des erreurs: @@ -68,6 +69,9 @@ ## Lorsqu'un cron job est supprimé, forcer une régénération complète des entrées de la base est ## donc nécessaire (sys_refresh_ref_cron.sh -force true) ## +## L'option show-only permet de lister les cronjobs installés sur les VM sans les enregistrer +## dans la base de données. +## ## Les informations de connexion à la base de données doivent être stockées dans ## le fichier PGPASSFILE sur sousetsuken au format suivant: ## @@ -176,27 +180,29 @@ function refresh_cronjobs COLOR="vert" fi fct_message ${MESSAGE} -color ${COLOR} - if [ ${#CRONJOB} -gt 0 ]; then - fct_message " Checking database:" - MINUTES=$(echo ${CRONJOB} | cut -d' ' -f1) - HOURS=$(echo ${CRONJOB} | cut -d' ' -f2) - DAYS=$(echo ${CRONJOB} | cut -d' ' -f3) - MONTHS=$(echo ${CRONJOB} | cut -d' ' -f4) - DAYSOFWEEK=$(echo ${CRONJOB} | cut -d' ' -f5) - COMMAND=$(echo ${CRONJOB} | cut -d' ' -f6-) - REQUEST_ID_PARAMS="host='${VM}' and s_user='${TETALAB_USER}' and minutes='${MINUTES}' and hours='${HOURS}' - and days='${DAYS}' and months='${MONTHS}' and daysofweek='${DAYSOFWEEK}' and command='${COMMAND}'" - RESULT=$(psql -q -t -h ${DB_HOST} -U ${DB_USER} -d ${DB_DATABASE} -c "select ID from - ref_cron where ${REQUEST_ID_PARAMS};") - if [ ${#RESULT} -eq 0 ]; then - fct_message " -> Cronjob not in database, inserting..." - REQUEST_INSERT_PARAMS="'${VM}', '${TETALAB_USER}', '${MINUTES}', - '${HOURS}', '${DAYS}', '${MONTHS}', '${DAYSOFWEEK}', '${COMMAND}'" - psql -q -t -h ${DB_HOST} -U ${DB_USER} -d ${DB_DATABASE} -c "insert into ref_cron - (\"host\", \"s_user\", \"minutes\", \"hours\", \"days\", \"months\", \"daysofweek\", \"command\") - values (${REQUEST_INSERT_PARAMS});" - else - fct_message " -> Cronjob already in database" + if [ "${show-only}" == "false" ]; then + if [ ${#CRONJOB} -gt 0 ]; then + fct_message " Checking database:" + MINUTES=$(echo ${CRONJOB} | cut -d' ' -f1) + HOURS=$(echo ${CRONJOB} | cut -d' ' -f2) + DAYS=$(echo ${CRONJOB} | cut -d' ' -f3) + MONTHS=$(echo ${CRONJOB} | cut -d' ' -f4) + DAYSOFWEEK=$(echo ${CRONJOB} | cut -d' ' -f5) + COMMAND=$(echo ${CRONJOB} | cut -d' ' -f6-) + REQUEST_ID_PARAMS="host='${VM}' and s_user='${TETALAB_USER}' and minutes='${MINUTES}' and hours='${HOURS}' + and days='${DAYS}' and months='${MONTHS}' and daysofweek='${DAYSOFWEEK}' and command='${COMMAND}'" + RESULT=$(psql -q -t -h ${DB_HOST} -U ${DB_USER} -d ${DB_DATABASE} -c "select ID from + ref_cron where ${REQUEST_ID_PARAMS};") + if [ ${#RESULT} -eq 0 ]; then + fct_message " -> Cronjob not in database, inserting..." + REQUEST_INSERT_PARAMS="'${VM}', '${TETALAB_USER}', '${MINUTES}', + '${HOURS}', '${DAYS}', '${MONTHS}', '${DAYSOFWEEK}', '${COMMAND}'" + psql -q -t -h ${DB_HOST} -U ${DB_USER} -d ${DB_DATABASE} -c "insert into ref_cron + (\"host\", \"s_user\", \"minutes\", \"hours\", \"days\", \"months\", \"daysofweek\", \"command\") + values (${REQUEST_INSERT_PARAMS});" + else + fct_message " -> Cronjob already in database" + fi fi fi done