crawl.bash 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. if [ -z "$1" ]; then
  3. >&2 echo "Sintassi: crawl.bash <directory in cui stanno crawl.php ecc.> [dopeers]"
  4. exit 1
  5. elif [ ! -d "$1" ]; then
  6. >&2 echo "«$1» non esiste o non è una directory, muoio."
  7. exit 1
  8. fi
  9. cd "$1"
  10. MAILCFG="../conf/mail.conf"
  11. LOGF="crawl.log"
  12. MAILF="mail"
  13. mailmta=`cat "$MAILCFG"|grep -P '^mta='|sed -e 's/^mta=//' -e 's/^"//' -e 's/"$//'`
  14. mailfrom=`cat "$MAILCFG"|grep -P '^from='|sed -e 's/^from=//' -e 's/^"//' -e 's/"$//'`
  15. mailto=`cat "$MAILCFG"|grep -P '^to='|sed -e 's/^to=//' -e 's/^"//' -e 's/"$//'`
  16. # $1: oggetto del messaggio; $2: file col corpo del messaggio
  17. function domail {
  18. echo "" | s-nail -q "$2" -s "$1" -S v15-compat -S from="$mailfrom" -S smtp-use-starttls -S mta="$mailmta" "$mailto"
  19. }
  20. # $1: comando; $2: logfile per l'output del comando
  21. function logcmd {
  22. init="$(date -R)"
  23. echo "$init: eseguo «$1»" >> $LOGF
  24. $1 &> $2
  25. ec=$?
  26. endt="$(date -R)"
  27. echo -n "$endt: fine esecuzione di «$1»: " >> $LOGF
  28. if [ $ec -eq 0 ]; then
  29. echo "riuscita!" >> $LOGF
  30. #domail "L’esecuzione di «$1» è riuscita! :-)" "Ciao, l’esecuzione di «$1», cominciata $init e finita $endt, è riuscita senza prubblemi :-)"
  31. else
  32. echo "ERRORE: $ec" >> $LOGF
  33. tail -n 20 $2 >> $LOGF
  34. tail -n 20 $2 > $MAILF
  35. domail "L’esecuzione di «$1», cominciata $init e finita $endt, NON È RIUSCITA (exit code: $ec) :-(" "$MAILF"
  36. fi
  37. }
  38. #logcmd "grep pippo gigi" "grepa.log"
  39. #logcmd "grep pippo bibi" "grepb.log"
  40. #exit
  41. echo "----------[ inizio esecuzione crawl.bash ]----------" >> $LOGF
  42. #tar cJf run-`date +%Y-%m-%d--%H.%M.%S`.tar.xz run/
  43. rm run/*
  44. logcmd "php mustool.php updstats" "mustool.updstats.log"
  45. [ "$2" == "dopeers" ] && logcmd "php peerscrawl.php -e peerscrawl.exclude -E" "peerscrawl.log"
  46. logcmd "php crawler.php -L none - -T warning" "crawler.log"
  47. logcmd "php mustool.php shuffle clean optimize" "mustool.shuffle-clean-optimize.log"
  48. exit 0