| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 # | 6 # |
| 7 # This script looks to see if a log file is zero length, or non | 7 # This script looks to see if a log file is zero length, or non |
| 8 # existent before writing something to stdout, so that we don't end up | 8 # existent before writing something to stdout, so that we don't end up |
| 9 # with empty entries that just look broken. | 9 # with empty entries that just look broken. |
| 10 | 10 |
| 11 max_lines=${2:-1000} | 11 max_lines=${2:-1000} |
| 12 file=$1 |
| 12 | 13 |
| 13 file=$1 | 14 [ "$file" = "/dev/stdin" ] && tail --lines=$max_lines "$file" && exit |
| 15 |
| 14 if [ -h "$file" ]; then | 16 if [ -h "$file" ]; then |
| 15 file="$(readlink -f $file)" | 17 file="$(readlink -f $file)" |
| 16 fi | 18 fi |
| 17 | 19 |
| 18 if [ -r "$file" -a -f "$file" ]; then | 20 if [ -r "$file" -a -f "$file" ]; then |
| 19 size=$(/bin/ls -s "$file") | 21 size=$(/bin/ls -s "$file") |
| 20 # Get the first field. | 22 # Get the first field. |
| 21 size=${size%% *} | 23 size=${size%% *} |
| 22 if [ $size -gt 0 ]; then | 24 if [ $size -gt 0 ]; then |
| 23 /usr/bin/tail --lines=$max_lines "$file" | 25 /usr/bin/tail --lines=$max_lines "$file" |
| 24 else | 26 else |
| 25 echo "<empty>" | 27 echo "<empty>" |
| 26 fi | 28 fi |
| 27 else | 29 else |
| 28 echo "<not available>" | 30 echo "<not available>" |
| 29 fi | 31 fi |
| OLD | NEW |