1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/bin/bash
- if [ -z "$1" ]; then
- >&2 echo "Sintassi: crawl.bash <directory in cui stanno crawl.php ecc.> [dopeers]"
- exit 1
- elif [ ! -d "$1" ]; then
- >&2 echo "«$1» non esiste o non è una directory, muoio."
- exit 1
- fi
- cd "$1"
- MAILCFG="../conf/mail.conf"
- LOGF="crawl.log"
- MAILF="mail"
- mailmta=`cat "$MAILCFG"|grep -P '^mta='|sed -e 's/^mta=//' -e 's/^"//' -e 's/"$//'`
- mailfrom=`cat "$MAILCFG"|grep -P '^from='|sed -e 's/^from=//' -e 's/^"//' -e 's/"$//'`
- mailto=`cat "$MAILCFG"|grep -P '^to='|sed -e 's/^to=//' -e 's/^"//' -e 's/"$//'`
- # $1: oggetto del messaggio; $2: file col corpo del messaggio
- function domail {
- echo "" | s-nail -q "$2" -s "$1" -S v15-compat -S from="$mailfrom" -S smtp-use-starttls -S mta="$mailmta" "$mailto"
- }
- # $1: comando; $2: logfile per l'output del comando
- function logcmd {
- init="$(date -R)"
- echo "$init: eseguo «$1»" >> $LOGF
- $1 &> $2
- ec=$?
- endt="$(date -R)"
- echo -n "$endt: fine esecuzione di «$1»: " >> $LOGF
- if [ $ec -eq 0 ]; then
- echo "riuscita!" >> $LOGF
- #domail "L’esecuzione di «$1» è riuscita! :-)" "Ciao, l’esecuzione di «$1», cominciata $init e finita $endt, è riuscita senza prubblemi :-)"
- else
- echo "ERRORE: $ec" >> $LOGF
- tail -n 20 $2 >> $LOGF
- tail -n 20 $2 > $MAILF
- domail "L’esecuzione di «$1», cominciata $init e finita $endt, NON È RIUSCITA (exit code: $ec) :-(" "$MAILF"
- fi
- }
- #logcmd "grep pippo gigi" "grepa.log"
- #logcmd "grep pippo bibi" "grepb.log"
- #exit
- echo "----------[ inizio esecuzione crawl.bash ]----------" >> $LOGF
- #tar cJf run-`date +%Y-%m-%d--%H.%M.%S`.tar.xz run/
- rm run/*
- logcmd "php mustool.php updstats" "mustool.updstats.log"
- [ "$2" == "dopeers" ] && logcmd "php peerscrawl.php -e peerscrawl.exclude -E" "peerscrawl.log"
- logcmd "php crawler.php -L none - -T warning" "crawler.log"
- logcmd "php mustool.php shuffle clean optimize" "mustool.shuffle-clean-optimize.log"
- exit 0
|