summaryrefslogtreecommitdiff
path: root/test.sh
blob: ef0206ccc87c96bf8dadb7edbc69cb0ce98bfa9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash

TITLE="Service Tests"
HOME="/home/ist"
TESTDIR="$HOME/service-tests"

. $HOME/.bashrc

DATE=`date +%y%m%d`
separator="============================"

LOGDIR="$HOME/log"
ERRLOG="$LOGDIR/$DATE-err.log"
LOG="$LOGDIR/$DATE.log"
MSG="$HOME/msg.log"
rm "$LOG" 2>/dev/null
rm "$ERRLOG" 2>/dev/null
rm "$MSG" 2>/dev/null

touch $LOG
touch $ERRLOG
touch $MSG

cd $TESTDIR
tests=(service-tests.rb)
for t in ${tests[@]}; do
  echo $separator | tee -a $LOG $MSG
  echo " "$t|tr [a-z] [A-Z] | tee -a $LOG $MSG
  echo " "`date` | tee -a $LOG $MSG
  echo $separator | tee -a $LOG $MSG
  echo ruby $t | tee -a $LOG $MSG
  # whole test output to logfile only
  ruby $t >> $LOG
  # take last occurrence of regex to end of the file
  awk '/^Finished in/ { buf = "" } { buf = buf "\n" $0 } END { print buf }' $LOG >> $MSG
  echo "" >> $LOG
done

# MAIL 
file="$HOME/scripts/recipients"
recipients=$(cat $file)
if grep -q "Error:" $LOG; then ERRMSG=" ERROR (`grep -c ' Error:' $LOG`)"; else ERRMSG=" OK "; fi
if grep -q "Failure:" $LOG; then FAILMSG=" FAIL (`grep -c ' Failure:' $LOG`)"; else FAILMSG=""; fi

for p in ${recipients[@]}; do
  #{ printf "To: $p\nSubject: [service tests] -$TITLE- $DATE $ERRMSG $FAILMSG\n"; cat $MSG; } | msmtp -a default $p
  { printf "To: $p\nSubject: [service tests] -$TITLE- $DATE $ERRMSG $FAILMSG\n"; cat $LOG; } | msmtp -a default $p
done

exit 0