3
I'm trying to write a script used on a buffer box that does full packet capture of network traffic. As it's for a fairly big network we split the captures into 100MB segments. At times of high network traffic oftentimes over a one minute period we will have multiple pcaps which cover that period.
So what I want to do is have a bash script that lets the analyst who is searching for something specify a date and time and how many minutes either side of it they want to search for files. Obviously I can do something like this -
ls -al | grep "Dec 1" | grep 02:00
ls -al | grep "Dec 1" | grep 02:01
and so on, get each result and grep each file individually for the specific keyword I'm looking for, but I'd like to be able to do a wider search for all files created within a time range and then grep each of them for the keyword.
I'm not entirely sure how to do that, any help would be appreciated.
The
find
command is your friend, especially the-ctime
,-mtime
and/or-newer
options. Do aman find
for more details. – Eric – 2013-12-01T02:30:28.460Yeah I've looked into using find, but that only works in days. We have 100% capture on the network for 30 days, averaging maybe, I dunno... thousands of 100mb segments per day. Doing searches over days of packets will put unnecessary strain on an already heavily loaded system. – Steve – 2013-12-01T02:34:33.997
1Culled from
man find
:-ctime n[smhdw] s second m minute (60 seconds) h hour (60 minutes) d day (24 hours) w week (7 days)
So you can specify units – Eric – 2013-12-01T02:40:39.200
I need to look for files in a RANGE of times on a specific date. Say between 11:20pm and 11:30pm on 3rd November. – Steve – 2013-12-01T02:42:27.567
1
Here is a method using find: http://aaronbonner.io/post/28969404367/find-and-delete-files-between-two-dates (just omit the delete portion of course).
– MaQleod – 2013-12-01T08:02:33.127I would use
stat
anddate
to find the files – glenn jackman – 2013-12-01T16:41:38.647If your version of
find
supports the-newer
test with a filename parameter, usetouch
to create files whose modification date/times are at the beginning and end of your desired range, and then use the expression-newer file2 ! –newer file1
. – Scott – 2013-12-02T22:16:19.593