69 lines
2.5 KiB
Bash
Executable File
69 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
PATH_BIN=/usr/local/sphinx/bin
|
|
PATH_LOG=/dbs/sphinxlog
|
|
PATH_SQL=/home/scripts/indexer/sql
|
|
MYSQL_HOST=192.168.3.30
|
|
MYSQL_USER=sphinx
|
|
MYSQL_PASS=indexer
|
|
|
|
# Is consolidated ?
|
|
output=$(mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS sdv1 < $PATH_SQL/consolidate-dir.sql)
|
|
idx='';
|
|
for line in "$output"; do
|
|
idx="$line";
|
|
done
|
|
# Suppression fin de ligne
|
|
idx=$(echo $idx|sed -e "s/^[idx ]*//g"||sed -e "s/[ ]*$//g")
|
|
|
|
# Lancement de l'indexation si la consolidation a eu lieu
|
|
if [ -n "$idx" ]; then
|
|
if [[ "$idx" > 0 ]]; then
|
|
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') === INDEXATION DIR" >> $PATH_LOG/indexer.log
|
|
|
|
# Nombre de lignes dans la table etablissements
|
|
output=$(mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS jo < $PATH_SQL/count-dir.sql)
|
|
nbC='';
|
|
for line in "$output"; do
|
|
nbC="$line"
|
|
done
|
|
# Suppression fin de ligne
|
|
nbC=$(echo $nbC|sed -e "s/^[nbC ]*//g"||sed -e "s/[ ]*$//g")
|
|
nbC=$(echo $(($nbC - 1000)))
|
|
|
|
# Nombre de lignes dans la table etablissements_tmp
|
|
output=$(mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS < $PATH_SQL/count-dirtmp.sql)
|
|
nbT='';
|
|
for line in "$output"; do
|
|
nbT="$line"
|
|
done
|
|
# Suppression fin de ligne
|
|
nbT=$(echo $nbT|sed -e "s/^[nbT ]*//g"||sed -e "s/[ ]*$//g")
|
|
|
|
if [ -z "$nbC" ]; then
|
|
elif [ -z "$nbT" ]; then
|
|
elif [ "$nbT" -gt "$nbC" ]; then
|
|
|
|
# Enregistrement Debut Indexation
|
|
mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS sdv1 -e "UPDATE sphinx_idx SET indexingBegin=NOW() WHERE id=$idx" >> $PATH_LOG/indexer.log
|
|
|
|
# Sphinx rotate
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - Sphinx - Debut" >> $PATH_LOG/indexer.log
|
|
$PATH_BIN/indexer --config /etc/sphinxsearch/sphinx.conf --rotate dir dir_phx >> $PATH_LOG/indexer.log
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - Sphinx - Fin" >> $PATH_LOG/indexer.log
|
|
|
|
# Rotation des tables MySQL
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - Rotation Table - Debut" >> $PATH_LOG/indexer.log
|
|
mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS jo < $PATH_SQL/rotate-dir.sql >> $PATH_LOG/indexer.log
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - Rotation Table - Fin" >> $PATH_LOG/indexer.log
|
|
|
|
# Enregistrement Fin Indexation
|
|
mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS sdv1 -e "UPDATE sphinx_idx SET indexingEnd=NOW() WHERE id=$idx" >> $PATH_LOG/indexer.log
|
|
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') === FIN INDEXATION DIR" >> $PATH_LOG/indexer.log
|
|
|
|
fi
|
|
|
|
fi
|
|
fi
|