Search in folder (in all files) for text - SSH ?

Discussion in 'PHP' started by thesurface, Apr 26, 2012.

  1. #1
    So i have this ssh cmd line:

    cat /var/log/httpd/error_log | grep ".ISC.SANS." | egrep -o '([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})' | awk '{print "iptables -I INPUT -s " $1 " -j DROP"}' | sort | uniq > drop.file

    For now it only search in oonly one file -> /var/log/httpd/error_log

    But how to rewrite it for to search for text in all files in a folder ?
     
    thesurface, Apr 26, 2012 IP
  2. Iann@LFCVPS

    Iann@LFCVPS Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Something like this would work if it was a directory full of error_logs for example:

    for i in /var/log/httpd/error_logs/*.log; do cat $i | grep ".ISC.SANS." | egrep -o '([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})' | awk '{print "iptables -I INPUT -s " $1 " -j DROP"}' | sort | uniq > drop.file

    That would do any file ending in .log, you could just to * for all files in that directory if all the files had the basic same structure that you were looking for.
     
    Iann@LFCVPS, Apr 26, 2012 IP