blob: c582ceb2e371797c1b1e6018a86acd8338d0b5e0 [file] [log] [blame]
#! /bin/sh
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# This script prints the last part of a syslog-timestamped file to the
# stdout. By default the content of /var/log/messages is printed. Options:
# --bytes N cap collected data at N bytes (default 512K)
#
# Note option order is important (TODO(sleffler) rewrite w/ shflags)
if [ "$1" = "--bytes" -o "$1" = "-c" ]; then
MAXDATA="$2"; shift; shift
else
MAXDATA='512K'
fi
LOGFILE=${1:-/var/log/messages}
# create list of files assuming normal log rotation
LOGFILES="${LOGFILE}"
BASENAME="${LOGFILE%%.*}"
EXTENSION="${LOGFILE#*.}"
if [ "${BASENAME}" = "${EXTENSION}" ]; then
EXTENSION=""
else
EXTENSION=".${EXTENSION}"
fi
for i in 1 2 3 4 5 6 7 8 9; do
FILE="${BASENAME}".$i${EXTENSION}
[ -f "${FILE}" ] || break
LOGFILES="${FILE} ${LOGFILES}"
done
cat ${LOGFILES} | tail -c ${MAXDATA}