简体   繁体   English

日志解析器:使用文本文件作为WHERE子句中的输入

[英]Log parser: Using a text file as an input in WHERE clause

I am working on a batch script where I am parsing IIS logs using Log Parser. 我正在使用批处理脚本在其中使用Log Parser解析IIS日志。 So, I have 2 questions here: 因此,我在这里有2个问题:

Q1. Q1。 What I want is, not to see the entries having username written in a text file. 我想要的是,不要看到在文本文件中写有用户名的条目。 So, one can update that text file without worrying about the code syntax. 因此,您可以更新该文本文件而不必担心代码语法。

In other words, Instead of putting every username(could be around 30-50) in 'WHERE' clause using 'AND' again & again, I will have a text file having list of usernames. 换句话说,我不会再一次使用“ AND”在“ WHERE”子句中输入每个用户名(大约30-50),而是拥有一个包含用户名列表的文本文件。

Code Example: 代码示例:

"LogParser.exe" -i:csv "SELECT DISTINCT date, cs-username, clientun, cs-uri-stem FROM D:\temp.csv WHERE NOT cs-username IN ('NULL';'abc';'def';'hij';'and_so_on')" >D:\final_output.txt -o:NAT -rtp:-1

I was trying to do this via sub-query first, but it is not supported in Log parser it seems. 我试图首先通过子查询来执行此操作,但似乎在日志解析器中不支持它。 I found OPENROWSET as a solution here but that doesn't seems to be working for me or may be I am not getting how to make it work. 我在这里找到了OPENROWSET作为解决方案但这似乎对我不起作用,或者可能是我没有使它起作用。 Other solution I found were for SQL and were not working for log parser. 我发现的其他解决方案是针对SQL的,不适用于日志解析器。

Q2. Q2。 I want the logs to be read between the dates mentioned. 我希望在提到的日期之间阅读日志。 So, I am taking a start and an end date from user in YYYY-MM-DD format and putting them in query 因此,我以YYYY-MM-DD格式从用户处获取开始和结束日期并将其置于查询中

"LogParser.exe" -i:iisw3c "SELECT DISTINCT cs-username, REVERSEDNS(C-IP), date, cs-uri-stem, FROM \logs\location\* WHERE date BETWEEN %date_1% AND %Date_2%" >D:\temp.csv -o:csv

The error I get here is: 我得到的错误是:

Error: WHERE clause: Semantic Error: left interval of BETWEEN operator ("'2016-02-15'") has a different type than operand ("date") 错误:WHERE子句:语义错误:BETWEEN运算符(“'2016-02-15'”)的左间隔与操作数(“日期”)的类型不同

Please note, the output file generated from the Q2 is used as input in Q1. 请注意,从Q2生成的输出文件将用作Q1的输入。

Q1: Instead of filtering the data using logparser use findstr and the /g:file /v switches to filter input files or output lines (depending on the case) Q1:代替使用logparser过滤数据,请使用findstr/g:file /v开关来过滤输入文件或输出行(取决于大小写)

Q2: Strings are not timestamps. Q2:字符串不是时间戳。 Use 采用

BETWEEN TO_TIMESTAMP('%date_1%','yyyy-MM-dd') AND TO_TIMESTAMP('%date_2%','yyyy-MM-dd')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM