#!/bin/bash logname=/home/test.log filename=/opt/test.txt count=0 while true; do LASTLINE=`date +"%Y-%m-%d %H:%M:%S"` ls $filename CURTIME=`date +"%Y-%m-%d %H:%M:%S"` Sys_data=`date -d "$CURTIME" +%s` In_data=`date -d "$LASTLINE" +%s` interval=`expr $Sys_data - $In_data` ((count +=1)) if (( $interval > 1 || $count==10 )) then count=0 echo "ls $filename cost time: $interval" >> $logname date >> $logname fi sleep 2 done