Browse Source

"test sys_refresh_ref_cron.sh"

master
Doug Le Tough 5 years ago
parent
commit
bae62c8a12
1 changed files with 34 additions and 21 deletions
  1. +34
    -21
      bin/sys_refresh_ref_cron.sh

+ 34
- 21
bin/sys_refresh_ref_cron.sh View File

@ -140,7 +140,14 @@ function check_config
done
}
function get_cronjobs
function get_db_info
{
DB_HOST=$(cat ${PGPASSFILE} | cut -d: -f1)
DB_DATABASE=$(cat ${PGPASSFILE} | cut -d: -f3)
DB_USER=$(cat ${PGPASSFILE} | cut -d: -f4)
}
function refresh_cronjobs
{
fct_message "Récupération des cronjobs:" -color jaune
for VM in ${TETALAB_VM[@]}
@ -162,35 +169,41 @@ function get_cronjobs
COLOR="cyan"
fi
fct_message ${MESSAGE} -color ${COLOR}
refresh_database "${CRONJOB}"
if [ ${#CRONJOB} -gt 0 ]; then
fct_message "Checking database:"
CRONJOB="$@"
MINUTES=$(echo ${CRONJOB} | cut -d' ' -f1)
HOURS=$(echo ${CRONJOB} | cut -d' ' -f2)
DAYS=$(echo ${CRONJOB} | cut -d' ' -f3)
MONTHS=$(echo ${CRONJOB} | cut -d' ' -f4)
DAYOFWEEK=$(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 daysofweek='${DAYSOFWEEKS}' and command='${COMMAND}'"
RESULT=$(psql -t -h ${DB_HOST} -U ${DB_USER} -d ${DB_DATABASE} -c "select ID from ref_cron where ${REQUEST_ID_PARAMS};")
if [ ${#RESULT} -gt 0 ];
fct_message "Cronjob not in database, inserting..."
REQUEST_INSERT_PARAMS=$(echo ${REQUEST_ID_PARAMS} | sed -s 's/and/,/g')
psql -t -h ${DB_HOST} -U ${DB_USER} -d ${DB_DATABASE} -c "insert in ref_cron values (${REQUEST_INSERT_PARAMS});")
else
fct_message "Cronjob already in database"
fi
fi
done
IFS=${IFS_BAK}
done
done
}
function refresh_database
{
fct_message "Updating database:"
CRONJOB="$@"
MINUTES=$(echo ${CRONJOB} | cut -d' ' -f1)
HOURS=$(echo ${CRONJOB} | cut -d' ' -f2)
DAYS=$(echo ${CRONJOB} | cut -d' ' -f3)
MONTHS=$(echo ${CRONJOB} | cut -d' ' -f4)
YEARS=$(echo ${CRONJOB} | cut -d' ' -f5)
COMMAND=$(echo ${CRONJOB} | cut -d' ' -f5-)
fct_message " * MINUTES: ${MINUTES}"
fct_message " * HOURS: ${HOURS}"
fct_message " * DAYS: ${DAYS}"
fct_message " * MONTHS: ${MONTHS}"
fct_message " * YEARS: ${YEARS}"
fct_message " * COMMAND: ${COMMAND}"
}
#------------------------------------------------------------------------------------------------------------------
# Traitement
#------------------------------------------------------------------------------------------------------------------
DB_HOST=""
DB_DATABASE=""
DB_USER=""
check_config
get_cronjobs
get_db_info
refresh_cronjobs
fct_erreur 0

Loading…
Cancel
Save