Maintainance script, unifying crawl.bash and backup.bash; first commit
This commit is contained in:
parent
63690b1cf6
commit
874479fac7
1 changed files with 57 additions and 0 deletions
57
web/clitools/maintain/maintain.bash
Executable file
57
web/clitools/maintain/maintain.bash
Executable file
|
@ -0,0 +1,57 @@
|
|||
#!/bin/bash
|
||||
|
||||
sname=`basename "${0}"`
|
||||
basedir=`dirname "${0}"`
|
||||
cd "${basedir}/.."
|
||||
mycfgfp="../conf/my.conf"
|
||||
mastcfgfp="../conf/mustard.ini"
|
||||
mailcfgfp="../conf/mail.conf"
|
||||
logfp="maintain.log"
|
||||
crlogfp="crawler.log"
|
||||
|
||||
dbname=`cat "${mastcfgfp}" | grep -P '^db_name=' | sed -e 's/^db_name=//' -e 's/^"//' -e 's/"$//'`
|
||||
|
||||
mailmta=`cat "${mailcfgfp}" | grep -P '^mta=' | sed -e 's/^mta=//' -e 's/^"//' -e 's/"$//'`
|
||||
mailfrom=`cat "${mailcfgfp}" | grep -P '^from=' | sed -e 's/^from=//' -e 's/^"//' -e 's/"$//'`
|
||||
mailto=`cat "${mailcfgfp}" | grep -P '^to=' | sed -e 's/^to=//' -e 's/^"//' -e 's/"$//'`
|
||||
|
||||
function log {
|
||||
echo `date "+%Y-%m-%d %H:%M:%S.%N"` "${1}" >> "${logfp}"
|
||||
}
|
||||
|
||||
# $1: comando; $2 file di log per stdout e stderr del comando
|
||||
function logcmd {
|
||||
log "Eseguo «${1}»..."
|
||||
$1 &>> $2
|
||||
ec=$?
|
||||
if [ "${ec}" == "0" ]; then
|
||||
log "Fatto, tutto ok :-)"
|
||||
else
|
||||
ok=0
|
||||
log "Errore: ${ec}."
|
||||
fi
|
||||
}
|
||||
|
||||
[ -f "${logfp}" ] && rm "${logfp}"
|
||||
ok=1
|
||||
log "[[[ Inizio esecuzione ${sname} ]]]"
|
||||
#tar cJf run-`date +%Y-%m-%d--%H.%M.%S`.tar.xz run/
|
||||
buff=`ls -1 run/`
|
||||
[ "${buff}" != "" ] && logcmd "rm run/*" "${logfp}"
|
||||
logcmd "php mustool.php updstats" "${logfp}"
|
||||
logcmd "php crawler.php -L none - -T warning" "${crlogfp}"
|
||||
logcmd "php mustool.php shuffle clean optimize" "${logfp}"
|
||||
ofp="maintain/backups/${dbname}_backup-`date +%Y-%m-%d--%H.%M.%S`.sql"
|
||||
logcmd "mysqldump --defaults-extra-file=${mycfgfp} -r ${ofp} ${dbname}" "${logfp}"
|
||||
if [ "${ec}" != "0" ]; then
|
||||
[ -f "${ofp}" ] && rm "${ofp}"
|
||||
else
|
||||
logcmd "xz -9 ${ofp}" "${logfp}"
|
||||
fi
|
||||
[ $ok -eq 1 ] && subj="maintain.bash: tutto ok :-)" || subj="maintain.bash: ci sono errori :-("
|
||||
body="[[[ ${logfp} ]]]\n\n"
|
||||
body+=`cat "${logfp}"`
|
||||
body+="\n\n[[[ Ultime 20 righe di ${crlogfp} ]]]\n\n"
|
||||
body+=`tail -n 20 "${crlogfp}"`
|
||||
echo -e "${body}" | s-nail -s "${subj}" -S v15-compat -S from="${mailfrom}" -S smtp-use-starttls -S mta="${mailmta}" "${mailto}"
|
||||
[ $ok -eq 1 ] && exit 0 || exit 1
|
Loading…
Reference in a new issue