3 # dumps out the log files according to the provided pattern, but makes sure that
4 # each one is dumped in chronological order, and any compressed logs are unpacked
7 function assemble_log_file()
11 # build an array of all the file names, in reverse order since we want the oldest
13 full_set=($(ls -1 -r "$logpath"*))
14 if [ ${#full_set[*]} -lt 1 ]; then
15 echo "No log files were found matching the pattern '$full_set'"
19 logdump="$(mktemp /tmp/$USER_logdump.XXXXXX)"
21 for logy in ${full_set[*]}; do
23 if [[ $logy =~ .*\.gz ]]; then
24 gzip -d -c "$logy" >>"$logdump"
26 cat "$logy" >>"$logdump"
39 if [ -z "$logpath" ]; then
40 echo "$(basename $0 .sh): Log file dumper"
42 echo "This script requires a log path, which should be the prefix of some log files"
43 echo "that it will dump out. All files matching the prefix are printed to standard"
44 echo "output, and the log entries will be printed in chronological order. Any"
45 echo "compressed log files will be unpacked first before printing."
48 echo -e "\t$(basename $0 .sh) /var/log/syslog"
53 assemble_log_file "$logpath"