|
#!/bin/sh # Copyright (c) 2007, Shandong University # All rights reserved. # # filename: handle_logfile # description: to give an example that demonstrates how to # handle the logfile. # Author: lqm
# One and only one parameter if [ $# != 1 ]; then echo "Usage: `basename $0` [filename]" exit 1 fi
# Source file must exist if [ -f $1 ]; then echo "$1 exists" else echo "$1 does not exist" exit 1 fi
# Get the number of lines LINE=`wc $1 | awk '{ print $1 }'` SIZE=`wc $1 | awk '{ print $3 }'` echo "line:$LINE, size:$SIZE"
# Create the test file cp $1 test cat $1 >> test
# Handle find test -size +${SIZE}c -exec echo "Find the desired logfile" {} \; \ && tail -n $LINE test >tmp \ && rm -f test \ && mv tmp test \ && diff $1 test \ && echo "Succeed!"
|