我希望能够从Apache日志文件中获取一行及其后面的所有行,以下是我希望简化的内容:
# Convert epoch to format used in log file
gtime=$(date -d @$etime +"%d/%b/%Y:%T") # "17/Nov/2015:16:36:45"
# Escape the slashes
g_tim=$(echo $gtime | sed 's/\//\\\//g') # "17\/Nov\/2015:16:36:45"
# Grab
lines=$(awk '/$g_tim/,0' access.log)
如果我不需要使用两个变量,那就更好了,而且我肯定还犯了其他各种错误。
日志文件的示例行:
djerk.nl:80 79.134.133.108 - - [17/Nov/2015:18:51:52 +0100] "GET /wordpress/2015/null HTTP/1.1" 103 16544 "http://www.djerk.nl/wordpress/2015/cisco-lacp-config-for-aruba-ap" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36"
djerk.nl:80 92.27.44.117 - - [17/Nov/2015:18:52:28 +0100] "GET /djerk_nl.pac HTTP/1.1" 403 1147 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36"