请协助。我正在尝试使用两个不同的日期范围在Ubuntu
fromauth.log
和syslog
in文件夹中搜索一些事件/var/log/
,我该怎么做?
我的代码如下所示,只有一个日期范围,但我需要其中的开始日期和结束日期:
#!/bin/bash
#User Input
echo -n -e "What's your Date range:"
read inputdate
#Save the search result in a file
sudo egrep "$inputdate" /var/log/auth.log > result.txt
#Display the result column wise with highlighted searching key word
column -t result.txt | more
echo -e "---------* End of Search Result! *-----------"
提前致谢。
答案1
为了详细说明 Panki 的建议,脚本将如下所示:
#!/bin/bash
#User Input
echo -n -e "What's your start date: "
read startdate
echo -n -e "What's your end date: "
read enddate
#Save the search result in a file
sed -n "/$startdate/,/$enddate/p" /var/log/auth.log > result.txt
#Display the result column wise with highlighted searching key word
column -t result.txt | more
echo -e "---------* End of Search Result! *-----------"