开发者

bash script for analyzin file on runtime

开发者 https://www.devze.com 2023-04-11 04:04 出处:网络
I want to do a bash script for analyzing a log file for errors. I was looking an efficient way 开发者_开发百科for getting the information as soon as they are written.

I want to do a bash script for analyzing a log file for errors. I was looking an efficient way 开发者_开发百科for getting the information as soon as they are written.

Can you suggest me some solutions?

Let's say my script will always running and getting each new line that is written in the log file, particulars events will generate alert or e-mail (that's not a problem).

Thanks!


Use tail -f to continuously get new lines and act on them via bash's read built-in.

tail -f logfile | while read line; do
      test "$line" = "nuclear meltdown" && echo "Run for your life!"
done
0

精彩评论

暂无评论...
验证码 换一张
取 消