douchao5864 2017-03-10 22:26 采纳率: 100%
浏览 82

如何从日志中获取我网站上所有唯一PHP GET的列表?

In my log I have many lines that look like this:

mysitename.net 1.23.45.67 - - [10/Mar/2017:20:28:38 +0000] "GET /foldername/special/somefile.php HTTP/1.1" 200 2012

Is there any way to grep all the unique PHP GETs into a file, so I have a list of any/all files on the server that were accessed?

I tried:

grep -i "GET [\w]+.php" mylogfile.txt > results.txt

but it does not return any rows.

  • 写回答

1条回答

  • dongpai6552 2017-03-10 22:36
    关注

    For grep, i would do it like this:

    $ a=$'mysitename.net 1.23.45.67 - - [10/Mar/2017:20:28:38 +0000] "GET /foldername/special/somefile.php HTTP/1.1" 200 2012' 
    $ grep -Eo 'GET.*php' <<<"$a"
    GET /foldername/special/somefile.php
    

    Personally, especially in mac, i would go for perl -pe oneliner, since works the same in all platforms, using regex group matching with backreference.

    In bellow example , the whole input string is divided in groups using parenthesis. Working with perl substitution (identical to sed) we can force perl to return to us only the third input group:

    $ perl -pe 's/(.*)(GET )(.*.php)(.*)/\3/g' <<<"$a" #if you want to include also the GET in your results then modify last part like .../\2\3/g'
    /foldername/special/somefile.php
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog