2014-02-18 4 views

답변

0

, 그것은 ... 파일로 표준 출력에서 ​​리디렉션 스크립트를 변경할 수 있습니다 ... 일어나고있는 당신 로그를 보여줍니다

#!/bin/bash 

GAP=10  #How long to wait 
LOGFILE=$1 #File to log to 

if [ "$#" -ne "1" ] 
then 
    echo "USAGE: ./watch-log.sh <file with absolute path>" 
    exit 1 
fi 


#Get current long of the file 
len=`wc -l $LOGFILE | awk '{ print $1 }'` 
echo "Current size is $len lines." 

while : 
do 
    if [ -N $LOGFILE ] 
    then 
     echo "`date`: New Entries in $LOGFILE: " 
     newlen=`wc -l $LOGFILE | awk ' { print $1 }'` 
     newlines=`expr $newlen - $len` 
     tail -$newlines $LOGFILE 
     len=$newlen 
    fi 
    sleep $GAP 
done 
exit 0 
0
위, 가정/tmp를 달성 할 수있을 것 find 명령을 사용하여

는 검색 경로 에없는 파일은 확장자가 .log에있는 로그

find $PATH_TO_SEARCH -type f -name "*.log" -cmin -60 -exec cp {} /tmp \; 
# Above single command can be configured as cron job. 
관련 문제