root/other-projects/the-macronizer/trunk/src/scripts-and-sql/macronLogToDB.bash.in @ 32755

Revision 32755, 3.6 KB (checked in by ak19, 17 months ago)

Western Wilson stuff. Final changes to get the mysql.props file running directly off the-macronizer checkout after ant's been run on it (and the 'ant logs-to-db-instructions' have been followed)

  • Property svn:executable set to *
Line 
1#! /bin/bash
2
3
4###################################
5
6# Set email_address only if you have permissions to run the mail client
7# on your linux box
8email_address=TYPE_NOTIFICATION_EMAIL
9
10
11exec_folder=@logfileproc.exec_folder@ #macronizer/web/classes (containing util.MacroniserLogFileProcessor)
12macronlogs_folder=@macronizer.logs@ #macronizer/web/logs
13processed_folder=@logfileproc.dir@/processed #/macronizer/logproc/processed
14reprocess_folder=@logfileproc.dir@/reprocess #/macronizer/logproc/reprocess
15errfile=@logfileproc.dir@/macronLogToDB.err #/macronizer/logproc/macronLogToDB.err
16jars_folder=@jarlibs.folder@ #macronizer/web/WEB-INF/lib
17mysqlprops_folder=@mysqlprops.dir@ #why doesn't @logfileproc.dir@ or /macronizer/web/WEB-INF/classes work? and only the basedir of the Macronizer?
18
19echo ""
20echo "In script $0 to process macron.log.* files"
21echo "  Note that any logfile named exactly 'macron.log' (instead of matching macron.log.*) will not be processed"
22
23# get rid of any old error files
24if [ -e $errfile ] ; then
25    rm $errfile
26fi
27
28if [ ! -d $macronlogs_folder ] ; then
29    echo "$macronlogs_folder does not exist. Terminating script $0." >> $errfile
30fi
31
32# create these directories iff they don't exist
33mkdir -p $processed_folder
34mkdir -p $reprocess_folder
35
36
37# "Bash does carry out filename expansion [1] -- a process known as globbing"
38# https://www.tldp.org/LDP/abs/html/globbingref.html
39# May be important: https://unix.stackexchange.com/questions/264926/is-it-a-sane-approach-to-back-up-the-ifs-variable
40IFS="$(printf '\n\t')"   # Remove space.
41
42#  Correct glob use:
43#  Always use for-loop, prefix glob, check if exists file.
44for logfile in $macronlogs_folder/macron.log.* ; do         # Use ./* ... NEVER bare * [EDIT: if in current folder?]
45    if [ -e "$logfile" ] ; then   # Check whether file exists.
46      echo "****** processing $logfile"     
47
48      # https://askubuntu.com/questions/625224/how-to-redirect-stderr-to-a-file
49
50      echo "Running command:"
51      echo "   java -cp \".:$mysqlprops_folder:$exec_folder:$jars_folder/mysql-connector-java-8.0.14.jar:$mysqlprops_folder\" util.MacroniserLogFileProcessor $logfile"
52      echo ""
53      java -cp ".:$mysqlprops_folder:$exec_folder:$jars_folder/mysql-connector-java-8.0.14.jar" util.MacroniserLogFileProcessor $logfile
54     
55      # The above returns 0 on success, -1 on failure
56      # if 0, then move $logfile to processed_folder
57      # and if -1, move to reprocess_folder
58      # https://askubuntu.com/questions/324423/how-to-access-the-last-return-value-in-bash
59      # https://www.tldp.org/LDP/abs/html/comparison-ops.html
60      result=$?
61      if [ "$result" -eq "0" ]; then
62      echo "Done processing $logfile, moving to $processed_folder"
63      mv $logfile "$processed_folder/."
64      else
65      echo "Need to reprocess $logfile, moving to $reprocess_folder" >> $errfile
66      mv $logfile "$reprocess_folder/."
67      fi
68  fi
69done
70
71echo "Finished processing macron.log.* files in $macronlogs_folder"
72echo ""
73
74# if email address provided, attempt to send email there
75if [ "$email_address" != "TYPE_NOTIFICATION_EMAIL" ]; then
76   
77    # If error file exists and has non-zero size, send email
78    # https://stackoverflow.com/questions/30080997/if-file-is-exists-and-is-not-empty-always-gives-me-the-false-value
79   
80    if [ -s $errfile ] ; then   
81    # send email with contents of error file
82    echo "cat $errfile | mail -s 'Macron.log to DB cron failure output' $email_address"
83    # TODO: uncomment on a machine that's allowed to email
84    cat $errfile | mail -s 'Macron.log to DB cron failure output' $email_address       
85   
86    echo "Supposed to have sent MAIL by now to $email_address"
87    fi
88fi
89
90
91
92
93
Note: See TracBrowser for help on using the browser.