"test sys_refresh_ref_cron.sh"

This commit is contained in:
Doug Le Tough 2017-07-25 13:10:51 +02:00
parent 8f80c1105b
commit 725f042087

View File

@ -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