事实上,我多年来一直在这样做。它使查询的可读性比从 cmd 提示符运行要好得多。这是我在 Cygwin Bash 中运行的示例 shell 脚本。
dumpBiz_All_aspx.sh:
#! /usr/bin/bash
# cd /cygdrive/c/apps/jsd/log_analysis
# . ./dumpBiz_All_aspx.sh
REPORT_NAME=all_aspx
ROOTDIR=D:\\_other\\access_log_analysis
LOGDIR=${ROOTDIR}\\new_server
LOGDATE=21*
SITE=mysite
DATE=`date +%y%m%d.%H%M%S`
OUTPUT_FILE=C:\\apps\\jsd\\log_analysis\\reports\\${SITE}_${REPORT_NAME}_${DATE}.csv
SQL=$(cat <<-EOF
SELECT To_Lowercase(cs-uri-stem) as Res, cs-method as Method, COUNT(*) as Hits
INTO ${OUTPUT_FILE}
FROM ${LOGDIR}\\u_ex${LOGDATE}.log
WHERE Res LIKE '%.aspx'
AND sc-status = 200
AND cs-host > ''
AND cs-host NOT LIKE '192%'
AND Res LIKE '/${SITE}/%'
GROUP BY Res, cs-method
ORDER BY Hits DESC
EOF
)
echo SQL = $SQL
echo
cat << EOF | sh
LogParser -i:IISW3C "${SQL}" -o:CSV
EOF
echo Launching $OUTPUT_FILE ...
cmd.exe /c start ${OUTPUT_FILE}
输出:
SQL = SELECT To_Lowercase(cs-uri-stem) as Res, cs-method as Method, COUNT(*) as Hits INTO C:\apps\jsd\log_analysis\reports\mysite_all_aspx_211005.155939.csv FROM D:\_other\access_log_analysis\new_server\u_ex21*.log WHERE Res LIKE '%.aspx' AND sc-status = 200 AND cs-host > '' AND cs-host NOT LIKE '192%' AND Res LIKE '/backoffice/%' GROUP BY Res, cs-method ORDER BY Hits DESC
Statistics:
-----------
Elements processed: 55780063
Elements output: 167
Execution time: 240.30 seconds (00:04:0.30)
Launching report: mysite_all_aspx_20211005.155442.csv ...
这会生成一个文件mysite_all_aspx_20211005.155442.csv
,并在默认的 csv 阅读器(如 Excel)中打开。