Skip to content

Instantly share code, notes, and snippets.

@lokal-profil
Last active August 22, 2018 09:22
Show Gist options
  • Select an option

  • Save lokal-profil/6f89d4a2fa708becf66581fcfe50aafc to your computer and use it in GitHub Desktop.

Select an option

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
#!/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;
@lokal-profil
Copy link
Copy Markdown
Author

clean_log.py can be found in this gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment