Advertisement
gocha

Print newly added lines from log file

Feb 28th, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.69 KB | None | 0 0
  1. #/bin/bash
  2.  
  3. logfile="linelog.log"
  4.  
  5. # remember the number of lines first
  6. logcount_oldln=`wc -l < ${logfile}`
  7. logcount_oldch=`wc -c < ${logfile}`
  8.  
  9. # do something and update the log
  10. date "+%Y/%m/%d %H:%M:%S" >> ${logfile}
  11. sleep 1
  12. date "+%Y/%m/%d %H:%M:%S" >> ${logfile}
  13. sleep 1
  14. date "+%Y/%m/%d %H:%M:%S" >> ${logfile}
  15.  
  16. # check the diff
  17. logcount_newln=`wc -l < ${logfile}`
  18. logcount_newch=`wc -c < ${logfile}`
  19. logcount_diffln=`expr ${logcount_newln} - ${logcount_oldln}`
  20. logcount_diffch=`expr ${logcount_newch} - ${logcount_oldch}`
  21. echo "added: ${logcount_diffch} bytes, ${logcount_diffln} lines"
  22.  
  23. # show it
  24. #tail -n ${logcount_diffln} ${logfile}
  25. tail -c ${logcount_diffch} ${logfile}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement