pipe cron output to logfile, fix sendreport script

This commit is contained in:
Enno Rehling 2018-07-07 10:45:11 +02:00
parent 82b1e16a82
commit 8af4b1fe29
4 changed files with 30 additions and 32 deletions

View File

@ -1,6 +1,5 @@
SCRIPTS=compress.sh send-bz2-report send-zip-report create-orders \ SCRIPTS=compress.sh send-bz2-report send-zip-report create-orders \
run-turn sendreports.sh run-turn sendreports.sh sendreport.sh
IGNORE=sendreport.sh
shellcheck: $(SCRIPTS) shellcheck: $(SCRIPTS)
shellcheck $(SCRIPTS) shellcheck $(SCRIPTS)

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
GAME=$1 GAME=$1
(
[ "$ENABLED" != "yes" ] && exit [ "$ENABLED" != "yes" ] && exit
[ -z ${ERESSEA} ] && ERESSEA=$HOME/eressea [ -z ${ERESSEA} ] && ERESSEA=$HOME/eressea
@ -58,3 +58,5 @@ $BIN/compress.sh $GAME $TURN
$BIN/sendreports.sh $GAME $BIN/sendreports.sh $GAME
$BIN/backup-eressea $GAME $TURN $BIN/backup-eressea $GAME $TURN
rm -f test/execute.lock rm -f test/execute.lock
) | tee -a $HOME/log/eressea.cron.log

View File

@ -1,10 +0,0 @@
#!/bin/bash
PATH=$ERESSEA/bin:$PATH
function abort() {
if [ $# -gt 0 ]; then
echo $@
fi
exit -1
}

View File

@ -1,11 +1,17 @@
#!/bin/bash #!/bin/bash
if [ -z $ERESSEA ]; then if [ -z "$ERESSEA" ]; then
echo "You have to define the \$ERESSEA environment variable to run $0" echo "You have to define the \$ERESSEA environment variable to run $0"
exit -2 exit -2
fi fi
source $HOME/bin/functions.sh
function abort() {
if [ $# -gt 0 ]; then
echo "$@"
fi
exit -1
}
GAME=$1 GAME=$1
EMAIL=$2 EMAIL=$2
@ -14,32 +20,33 @@ PASSWD=$4
#echo "$GAME $EMAIL $FACTION $PASSWD" >> /tmp/report.log #echo "$GAME $EMAIL $FACTION $PASSWD" >> /tmp/report.log
function reply() { function reply() {
echo $@ | mutt -s "Reportnachforderung Partei ${FACTION}" $EMAIL echo "$@" | mutt -s "Reportnachforderung Partei ${FACTION}" "$EMAIL"
abort $@ abort "$@"
} }
LOCKFILE=$ERESSEA/.report.lock LOCKFILE="$ERESSEA/.report.lock"
[ -e $LOCKFILE ] && reply "lockfile exists. wait for mail delivery to finish." [ -e "$LOCKFILE" ] && reply "lockfile exists. wait for mail delivery to finish."
REPLYTO='accounts@eressea.de' echo "$(date):report:$GAME:$EMAIL:$FACTION:$PASSWD" >> "$ERESSEA/request.log"
echo `date`:report:$GAME:$EMAIL:$FACTION:$PASSWD >> $ERESSEA/request.log cd "$ERESSEA" || exit
checkpasswd.py "game-$GAME/passwd" "$FACTION" "$PASSWD" || reply "Das Passwort fuer die Partei $FACTION ist ungueltig"
cd $ERESSEA cd "$ERESSEA/game-$GAME/reports" || exit
checkpasswd.py game-$GAME/passwd $FACTION $PASSWD || reply "Das Passwort fuer die Partei $FACTION ist ungueltig" if [ ! -e "${FACTION}.sh" ]; then
cd $ERESSEA/game-$GAME/reports
if [ ! -e ${FACTION}.sh ]; then
echo "Der Report für Partei $FACTION kann wegen technischer Probleme leider nicht nachgefordert werden: No such file ${FACTION}.sh" \ echo "Der Report für Partei $FACTION kann wegen technischer Probleme leider nicht nachgefordert werden: No such file ${FACTION}.sh" \
| mutt -s "Reportnachforderung Partei ${FACTION}" $EMAIL | mutt -s "Reportnachforderung Partei ${FACTION}" "$EMAIL"
exit exit
fi fi
source ${FACTION}.sh $EMAIL || reply "Unbekannte Partei $FACTION" bash "${FACTION}.sh" "$EMAIL" || reply "Unbekannte Partei $FACTION"
if [ -e $ERESSEA/game-$GAME/eressea.db ]; then if [ -e "$ERESSEA/game-$GAME/eressea.db" ]; then
SQL="select email from faction f left join faction_data fd on fd.faction_id=f.id where f.game_id=$GAME AND fd.code='$FACTION' and fd.turn=(select max(turn) from faction_data fx where fx.faction_id=f.id)" SQL="select email from faction f left join faction_data fd on fd.faction_id=f.id where f.game_id=$GAME AND fd.code='$FACTION' and fd.turn=(select max(turn) from faction_data fx where fx.faction_id=f.id)"
OWNER=$(sqlite3 $ERESSEA/game-$GAME/eressea.db "$SQL") OWNER=$(sqlite3 "$ERESSEA/game-$GAME/eressea.db" "$SQL")
if [ ! -z "$OWNER" ]; then
echo "Der Report Deiner Partei wurde an ${EMAIL} gesandt." \ echo "Der Report Deiner Partei wurde an ${EMAIL} gesandt." \
| mutt -s "Reportnachforderung Partei ${FACTION}" $OWNER | mutt -s "Reportnachforderung Partei ${FACTION}" "$OWNER"
fi
fi fi