logfiles

Shellscript to monitor a log file if keyword triggers then execute a command?

╄→гoц情女王★ 提交于 2019-11-28 03:23:50
Is there a cheap way to monitor a log file like tail -f log.txt , then if something like [error] appears, execute a command? Thank you. tail -fn0 logfile | \ while read line ; do echo "$line" | grep "pattern" if [ $? = 0 ] then ... do something ... fi done I also found that you can use awk to monitor for pattern and perform some action when pattern is found: tail -fn0 logfile | awk '/pattern/ { print | "command" }' This will execute command when pattern is found in the log. Command can be any unix command including shell scripts or anything else. Ari Maniatis An even more robust approach is

Read the log file (*.LDF) in SQL Server 2008

断了今生、忘了曾经 提交于 2019-11-27 22:33:53
I'm searching for a way to read the SQL Server 2008 log file, not to show the information, but to read the meaning of the symbols and the structure of the LOG table. I'm using DBCC LOG('my_table', 3) . Ardalan Shahgholi See my answer in this Stack Overflow post: How can I view SQL Server 2005 Transaction log file Or Use this command: Select * from ::fn_dblog(null,null) And for more information, see How Do You Decode A Simple Entry in the Transaction Log . JdMR First of all, in order to be able to read any meaningful data your database needs to be in full recovery mode. Otherwise you probably

extract last 10 minutes from logfile [duplicate]

ぃ、小莉子 提交于 2019-11-27 05:47:49
问题 This question already has an answer here: Filter log file entries based on date range 3 answers Trying to find a simple way for watching for recent events (from less than 10 minutes), I've tried this: awk "/^$(date --date="-10 min" "+%b %_d %H:%M")/{p++} p" /root/test.txt but it doesn't work as expected... Log files are in form : Dec 18 09:48:54 Blah Dec 18 09:54:47 blah bla Dec 18 09:55:33 sds Dec 18 09:55:38 sds Dec 18 09:57:58 sa Dec 18 09:58:10 And so on... 回答1: You can match the date

Shellscript to monitor a log file if keyword triggers then execute a command?

拥有回忆 提交于 2019-11-27 05:07:34
问题 Is there a cheap way to monitor a log file like tail -f log.txt , then if something like [error] appears, execute a command? Thank you. 回答1: tail -fn0 logfile | \ while read line ; do echo "$line" | grep "pattern" if [ $? = 0 ] then ... do something ... fi done 回答2: I also found that you can use awk to monitor for pattern and perform some action when pattern is found: tail -fn0 logfile | awk '/pattern/ { print | "command" }' This will execute command when pattern is found in the log. Command

Read the log file (*.LDF) in SQL Server 2008

烈酒焚心 提交于 2019-11-27 04:35:17
问题 I'm searching for a way to read the SQL Server 2008 log file, not to show the information, but to read the meaning of the symbols and the structure of the LOG table. I'm using DBCC LOG('my_table', 3) . 回答1: See my answer in this Stack Overflow post: How can I view SQL Server 2005 Transaction log file Or Use this command: Select * from ::fn_dblog(null,null) And for more information, see How Do You Decode A Simple Entry in the Transaction Log . 回答2: First of all, in order to be able to read any

Get last n lines of a file with Python, similar to tail

末鹿安然 提交于 2019-11-26 01:20:02
问题 I\'m writing a log file viewer for a web application and for that I want to paginate through the lines of the log file. The items in the file are line based with the newest item on the bottom. So I need a tail() method that can read n lines from the bottom and supports an offset. What I came up with looks like this: def tail(f, n, offset=0): \"\"\"Reads a n lines from f with an offset of offset lines.\"\"\" avg_line_length = 74 to_read = n + offset while 1: try: f.seek(-(avg_line_length * to