From 7a8ab52cf4dac45c0b53abaa7ad8e2191ca7cde3 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Tue, 12 Mar 2013 19:35:35 -0400 Subject: [PATCH] karflax --- scripts/system/dump_logs.sh | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 scripts/system/dump_logs.sh diff --git a/scripts/system/dump_logs.sh b/scripts/system/dump_logs.sh new file mode 100644 index 00000000..0311de8b --- /dev/null +++ b/scripts/system/dump_logs.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# dumps out the log files according to the provided pattern, but makes sure that +# each one is dumped in chronological order, and any compressed logs are unpacked +# first. + +function assemble_log_file() +{ + logpath="$1"; shift + + # build an array of all the file names, in reverse order since we want the oldest + # files listed first. + full_set=($(ls -1 -r "$logpath"*)) + if [ ${#full_set[*]} -lt 1 ]; then + echo "No log files were found matching the pattern '$full_set'" + exit 1 + fi + + logdump="$(mktemp /tmp/$USER_logdump.XXXXXX)" + + for logy in ${full_set[*]}; do +#echo logy is $logy + if [[ $logy =~ .*\.gz ]]; then + gzip -d -c "$logy" >>"$logdump" + else + cat "$logy" >>"$logdump" + fi + done + + cat "$logdump" + \rm -f "$logdump" +} + + +############## + +logpath="$1"; shift + +if [ -z "$logpath" ]; then + echo "$(basename $0 .sh): Log file dumper" + echo + echo "This script requires a log path, which should be the prefix of some log files" + echo "that it will dump out. All files matching the prefix are printed to standard" + echo "output, and the log entries will be printed in chronological order. Any" + echo "compressed log files will be unpacked first before printing." + echo + echo "Example:" + echo -e "\t$(basename $0 .sh) /var/log/syslog" + echo + exit 1 +fi + +assemble_log_file "$logpath" + + -- 2.34.1