[32747] | 1 | #! /bin/bash
|
---|
| 2 |
|
---|
| 3 |
|
---|
[32753] | 4 | ###################################
|
---|
[32747] | 5 |
|
---|
[32753] | 6 | # Set email_address only if you have permissions to run the mail client
|
---|
| 7 | # on your linux box
|
---|
[32755] | 8 | email_address=TYPE_NOTIFICATION_EMAIL
|
---|
[32747] | 9 |
|
---|
| 10 |
|
---|
[32753] | 11 | [email protected]_folder@ #macronizer/web/classes (containing util.MacroniserLogFileProcessor)
|
---|
| 12 | [email protected]@ #macronizer/web/logs
|
---|
| 13 | [email protected]@/processed #/macronizer/logproc/processed
|
---|
| 14 | [email protected]@/reprocess #/macronizer/logproc/reprocess
|
---|
| 15 | [email protected]@/macronLogToDB.err #/macronizer/logproc/macronLogToDB.err
|
---|
| 16 | [email protected]@ #macronizer/web/WEB-INF/lib
|
---|
[32755] | 17 | [email protected]@ #why doesn't @logfileproc.dir@ or /macronizer/web/WEB-INF/classes work? and only the basedir of the Macronizer?
|
---|
[32747] | 18 |
|
---|
[32749] | 19 | echo ""
|
---|
| 20 | echo "In script $0 to process macron.log.* files"
|
---|
| 21 | echo " Note that any logfile named exactly 'macron.log' (instead of matching macron.log.*) will not be processed"
|
---|
[32747] | 22 |
|
---|
| 23 | # get rid of any old error files
|
---|
| 24 | if [ -e $errfile ] ; then
|
---|
| 25 | rm $errfile
|
---|
| 26 | fi
|
---|
| 27 |
|
---|
| 28 | if [ ! -d $macronlogs_folder ] ; then
|
---|
| 29 | echo "$macronlogs_folder does not exist. Terminating script $0." >> $errfile
|
---|
| 30 | fi
|
---|
| 31 |
|
---|
| 32 | # create these directories iff they don't exist
|
---|
| 33 | mkdir -p $processed_folder
|
---|
| 34 | mkdir -p $reprocess_folder
|
---|
| 35 |
|
---|
[32749] | 36 |
|
---|
[32747] | 37 | # "Bash does carry out filename expansion [1] -- a process known as globbing"
|
---|
| 38 | # https://www.tldp.org/LDP/abs/html/globbingref.html
|
---|
[32755] | 39 | # May be important: https://unix.stackexchange.com/questions/264926/is-it-a-sane-approach-to-back-up-the-ifs-variable
|
---|
[32747] | 40 | IFS="$(printf '\n\t')" # Remove space.
|
---|
| 41 |
|
---|
| 42 | # Correct glob use:
|
---|
| 43 | # Always use for-loop, prefix glob, check if exists file.
|
---|
[32749] | 44 | for 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"
|
---|
[32747] | 47 |
|
---|
| 48 | # https://askubuntu.com/questions/625224/how-to-redirect-stderr-to-a-file
|
---|
| 49 |
|
---|
[32749] | 50 | echo "Running command:"
|
---|
[32755] | 51 | echo " java -cp \".:$mysqlprops_folder:$exec_folder:$jars_folder/mysql-connector-java-8.0.14.jar:$mysqlprops_folder\" util.MacroniserLogFileProcessor $logfile"
|
---|
[32749] | 52 | echo ""
|
---|
[32755] | 53 | java -cp ".:$mysqlprops_folder:$exec_folder:$jars_folder/mysql-connector-java-8.0.14.jar" util.MacroniserLogFileProcessor $logfile
|
---|
[32749] | 54 |
|
---|
[32747] | 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
|
---|
| 69 | done
|
---|
| 70 |
|
---|
[32753] | 71 | echo "Finished processing macron.log.* files in $macronlogs_folder"
|
---|
[32749] | 72 | echo ""
|
---|
[32747] | 73 |
|
---|
[32755] | 74 | # if email address provided, attempt to send email there
|
---|
| 75 | if [ "$email_address" != "TYPE_NOTIFICATION_EMAIL" ]; then
|
---|
[32747] | 76 |
|
---|
[32755] | 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
|
---|
[32747] | 88 | fi
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 |
|
---|
[32755] | 92 |
|
---|
| 93 |
|
---|