Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>yes, there are multiple ways to do this. Here is how I would go about this. For starters, no need to pipe the output of cat, just open the log file with <code>awk</code>. </p> <pre><code>awk -vDate=`date -d'now-2 hours' +[%d/%b/%Y:%H:%M:%S` '$4 &gt; Date {print Date, $0}' access_log </code></pre> <p>assuming your log looks like mine (they're configurable) than the date is stored in field 4. and is bracketed. What I am doing above is finding everything within the last 2 hours. <code>Note the -d'now-2 hours'</code> or translated literally now minus 2 hours which for me looks something like this: <code>[10/Oct/2011:08:55:23</code></p> <p>So what I am doing is storing the formatted value of two hours ago and comparing against field four. The conditional expression should be straight forward.I am then printing the Date, followed by the Output Field Separator (OFS -- or space in this case) followed by the whole line $0. You could use your previous expression and just print $1 (the ip addresses) </p> <pre><code>awk -vDate=`date -d'now-2 hours' +[%d/%b/%Y:%H:%M:%S` '$4 &gt; Date {print $1}' | sort |uniq -c |sort -n | tail </code></pre> <p>If you wanted to use a range specify two date variables and construct your expression appropriately. </p> <p>so if you wanted do find something between 2-4hrs ago your expression might looks something like this</p> <pre><code>awk -vDate=`date -d'now-4 hours' +[%d/%b/%Y:%H:%M:%S` -vDate2=`date -d'now-2 hours' +[%d/%b/%Y:%H:%M:%S` '$4 &gt; Date &amp;&amp; $4 &lt; Date2 {print Date, Date2, $4} access_log' </code></pre> <p>Here is a question I answered regarding dates in bash you might find helpful. <a href="https://stackoverflow.com/questions/6497525/print-date-for-the-monday-of-the-current-week-in-bash/6497622#6497622">Print date for the monday of the current week (in bash)</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload