From 725f04208790abcb08d73dcce1940891ad5aaf24 Mon Sep 17 00:00:00 2001 From: Doug Le Tough Date: Tue, 25 Jul 2017 13:10:51 +0200 Subject: [PATCH] "test sys_refresh_ref_cron.sh" --- bin/sys_refresh_ref_cron.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/bin/sys_refresh_ref_cron.sh b/bin/sys_refresh_ref_cron.sh index c2c33e3..b9a269e 100755 --- a/bin/sys_refresh_ref_cron.sh +++ b/bin/sys_refresh_ref_cron.sh @@ -147,6 +147,15 @@ function get_db_info DB_USER=$(cat ${PGPASSFILE} | cut -d: -f4) } +function clean_table +{ + if [ "${force}" == "true" ]; then + fct_message "Option -force activée: Suppression des données dans la table." -color orange + SQL="delete from ref_cron where id > 0;" + psql -t -h ${DB_HOST} -U ${DB_USER} -d ${DB_DATABASE} -c "${SQL}" + fi +} + function refresh_cronjobs { fct_message "Récupération des cronjobs:" -color jaune @@ -168,7 +177,7 @@ function refresh_cronjobs fi fct_message ${MESSAGE} -color ${COLOR} if [ ${#CRONJOB} -gt 0 ]; then - fct_message "Checking database:" + fct_message " Checking database:" MINUTES=$(echo ${CRONJOB} | cut -d' ' -f1) HOURS=$(echo ${CRONJOB} | cut -d' ' -f2) DAYS=$(echo ${CRONJOB} | cut -d' ' -f3) @@ -180,14 +189,14 @@ function refresh_cronjobs RESULT=$(psql -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..." + fct_message " -> Cronjob not in database, inserting..." REQUEST_INSERT_PARAMS="'${VM}', '${TETALAB_USER}', '${MINUTES}', '${HOURS}', '${DAYS}', '${MONTHS}', '${DAYSOFWEEKS}', '${COMMAND}'" - psql -e -t -h ${DB_HOST} -U ${DB_USER} -d ${DB_DATABASE} -c "insert into ref_cron + psql -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" + fct_message " -> Cronjob already in database" fi fi done @@ -206,5 +215,6 @@ DB_USER="" check_config get_db_info +clean_table refresh_cronjobs fct_erreur 0