Link to home
Start Free TrialLog in
Avatar of joaotelles
joaotellesFlag for United States of America

asked on

Shell - noding files from the current day

Hi,

Im using this command to get some info from the files below:

> find /var/opt/smarttreee/dpa/log/event/output/TrafficErrorEvents* -type f -mtime -7 -print0 | xargs -0 grep SmartPrM | wc -l

Is there a way for it not to take the files that has the timestamp of the current day?

For example, lets say I have files like this:

TrafficErrorEvents20130917.0689
.
.
TrafficErrorEvents20130921.0689
TrafficErrorEvents20130922.0690
TrafficErrorEvents20130923.0691
TrafficErrorEvents20130923.0692
TrafficErrorEvents20130924.0693
TrafficErrorEvents20130924.0694

Using the command above Im reading the files from the day 09/24 to the 09/17  (considering today as 09/24)

So, Is there a way for it to read the files from 09/23 to 09/17 ? NOT reading the files from 09/24 ?

Tks,
Joao Telles
Avatar of Tintin
Tintin

Add the -a ! -mtime 0.  Also corrected your inefficient file globbing and unnecessary use of wc

find /var/opt/smarttreee/dpa/log/event/output -name "TrafficErrorEvents*" -type f -mtime -7 -a ! -mtime 0 -print0 | xargs -0 grep -c SmartPrM 

Open in new window

Avatar of joaotelles

ASKER

Hi,

I ran the command but I have some questions:

> find /var/opt/smarttreee/dpa/log/event/output -name "TrafficErrorEvents*" -type f -mtime -7 -a ! -mtime 0 -print0 | xargs -0 grep -c SmartPrM

The output was like this:
/var/opt/smarttreee/dpa/log/event/output/TrafficErrorEvents20130918.0529:4
/var/opt/smarttreee/dpa/log/event/output/TrafficErrorEvents20130921.0633:46
/var/opt/smarttreee/dpa/log/event/output/TrafficErrorEvents20130918.0553:3
/var/opt/smarttreee/dpa/log/event/output/TrafficErrorEvents20130920.0593:40
/var/opt/smarttreee/dpa/log/event/output/TrafficErrorEvents20130923.0679:33
/var/opt/smarttreee/dpa/log/event/output/TrafficErrorEvents20130921.0626:29
.
.
.

====

But I need the total of all files, not individually like this... can it be done?


Also I noticed that it analized: 183 files.

find /var/opt/smarttrust/dpa/log/event/output -name "TrafficErrorEvents*" -type f -mtime -7 -a ! -mtime 0 -print0 | xargs -0 grep -c SmartProv_TEXTSM | wc -l
183

But I have 226 files from 09/24 to 09/18 (seven days before today)... Not sure it didnt analized all files...

Maybe your command works getting the last 24hrs instead of picking the files per timestamp?

If it works using the clock (24hrs before now).. If run it now, some files of yesterday will not be analized and this is not the goal here..

Tks,
Joao
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if daystart is unavailable, you can always touch a file at midnight and use -newer flag (negated)

if you are using daily log rotations and a system that supports ctime, ctimes will work out-of the box
Tks.