Last active
August 22, 2018 09:22
-
-
Save lokal-profil/6f89d4a2fa708becf66581fcfe50aafc to your computer and use it in GitHub Desktop.
Shell script for chopping heritage logs to only the last copleted run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Script to make a local copy of the last complete log | |
| # make a local copy of the logs | |
| cp /data/project/heritage/logs/update_monuments.log ./raw.log; | |
| # cut log at last complete | |
| last_complete=$(grep --binary-files=text -n "Done with the update!" raw.log | tail -n1 | cut -f1 -d:); | |
| head -n "$last_complete" raw.log > tmp.log; | |
| # keep only last log | |
| log_length=$(wc -l tmp.log | cut -f1 -d' '); | |
| last_start=$(grep --binary-files=text -n "Starting full monument update" tmp.log | tail -n1 | cut -f1 -d:); | |
| cut_line=$((log_length - last_start + 1)); | |
| tail -n "$cut_line" tmp.log > tmp2.log; | |
| # output info on isolated log | |
| log_length=$(wc -l tmp2.log | cut -f1 -d' '); | |
| start_date=$(head -n1 tmp2.log | cut -f1 -d'_'); | |
| start_time=$(head -n1 tmp2.log | cut -f1 -d' '); | |
| end_time=$(tail -n1 tmp2.log | cut -f1 -d' '); | |
| outname="update_monuments_$start_date.log"; | |
| mv tmp2.log "$outname"; | |
| echo "$outname: ($start_time -- $end_time) $log_length lines"; | |
| python clean_log.py "$outname"; | |
| # clean up | |
| rm raw.log; | |
| rm tmp.log; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
clean_log.pycan be found in this gist