proving git release script isn't busted
[feisty_meow.git] / scripts / system / dump_log.sh
1 #!/bin/bash
2
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
5 # first.
6
7 function assemble_log_file()
8 {
9   logpath="$1"; shift
10
11   # build an array of all the file names, in reverse order since we want the oldest
12   # files listed first.
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'"
16     exit 1
17   fi
18
19   logdump="$(mktemp /tmp/$USER_logdump.XXXXXX)"
20
21   for logy in ${full_set[*]}; do
22 #echo logy is $logy
23     if [[ $logy =~ .*\.gz ]]; then
24       gzip -d -c "$logy" >>"$logdump"
25     else
26       cat "$logy" >>"$logdump"
27     fi
28   done
29
30   cat "$logdump"
31   \rm -f "$logdump"
32 }
33
34
35 ##############
36
37 logpath="$1"; shift
38
39 if [ -z "$logpath" ]; then
40   echo "$(basename $0 .sh): Log file dumper"
41   echo
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."
46   echo
47   echo "Example:"
48   echo -e "\t$(basename $0 .sh) /var/log/syslog"
49   echo
50   exit 1
51 fi
52
53 assemble_log_file "$logpath"
54
55