Shell函数在特定时间为特定字符串定制日志文件 [英] Shell function to tail a log file for a specific string for a specific time
本文介绍了Shell函数在特定时间为特定字符串定制日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要做以下事情来确保我的应用程序服务器是
- 为特定字符串填写日志文件
- 保持阻止状态,直到打印字符串为止
- 然而,如果字符串未打印约20分钟,则退出并抛出异常消息,如服务器花费了20分钟如果字符串打印在日志文件中,退出循环并继续。
<有没有办法在一个while循环中包含超时?
解决方案
#!/ bin / bash
tail -f logfile | grep'certain_word'|读-t 1200 dummy_var
[$? -eq 0]&& echo'ok'|| echo'server not up'
这会读取任何写入日志文件的内容,搜索certain_word,如果全部回显是好的,否则在等待1200秒(20分钟)后就会报怨。
I need to the following things to make sure my application server is
- Tail a log file for a specific string
- Remain blocked until that string is printed
- However if the string is not printed for about 20 mins quit and throw and exception message like "Server took more that 20 mins to be up"
- If string is printed in the log file quit the loop and proceed.
Is there a way to include time outs in a while loop ?
解决方案
#!/bin/bash
tail -f logfile | grep 'certain_word' | read -t 1200 dummy_var
[ $? -eq 0 ] && echo 'ok' || echo 'server not up'
This reads anything written to logfile, searches for certain_word, echos ok if all is good, otherwise after waiting 1200 seconds (20 minutes) it complains.
这篇关于Shell函数在特定时间为特定字符串定制日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文