Find and awk with today's date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and awk with today's date
# 1  
Old 01-22-2015
Find and awk with today's date

Hi All,
Solaris 10 o/s
With your help I developed the following script.
Code:
find /oracle/diag/rdbms/*/*/trace -type f -name '*d00*.trc' -mtime 0  -exec   egrep –c  'NS Primary Error' '{}' '+'

which returns the counts I needed nelow:
Code:
/oracle/diag/rdbms/musidp/musidp/trace/abcdef_d001_21751.trc:15
/oracle/diag/rdbms/musidp/musidp/trace/ abcdef _d000_21750.trc:20
/oracle/diag/rdbms/abcdef/abcdef/trace/abcdef_d001_22002.trc:1524
/oracle/diag/rdbms/abcdef/abcdef/trace/abcdef_d000_22001.trc:1291

There is one additional requirement and those counts can only be related to today’s date. Right now those counts include several dates in each trace file. I have come up with the following but it returns no data. I know for a fact that when I inspected the trace files I see that date 2015-01-22 in the trace file.

Code:
find /oracle/diag/rdbms/*/*/trace -type f -name '*d00*.trc' -mtime 0  -exec egrep  'NS Primary Error' '{}' '+' | awk '/2015-01-22/ {print}'

Is there some other way to write this
Any assistance would be appreciated.
Thanks

Last edited by vgersh99; 01-22-2015 at 01:55 PM.. Reason: code tags, please!
# 2  
Old 01-22-2015
try this:
Code:
find /oracle/diag/rdbms/*/*/trace -type f -name '*d00*.trc' -mtime 0  -exec awk '/2015-01-22/ && /NS Primary Error/' '{}' '+'

# 3  
Old 01-22-2015
Here is a solution that displays the count of lines containing "NS Primary Error" within all files containing "2015-01-22":

Code:
find /oracle/diag/rdbms/*/*/trace -type f -name '*d00*.trc' -mtime 0  -exec awk '
    function pa() { if(FN) print FN":"CNT }
    FNR==1{pa(); FN=CNT=x }
    /2015-01-22/ {FN=FILENAME}
    /NS Primary Error/{CNT++}
    END{pa()}' '{}' '+'

# 4  
Old 01-23-2015
Morning,

Thanks for this. I will run it and get back to you on the results today.

regards
al

---------- Post updated at 07:11 AM ---------- Previous update was at 06:57 AM ----------

Morning Chubler,

I ran your script and it errored out. See below.

Code:
-trace> find /oracle/diag/rdbms/*/*/trace -type f -name '*d00*.trc' -mtime 0  -exec awk '
>     function pa() { if(FN) print FN":"CNT }
>     FNR==1{pa(); FN=CNT=x }
>     /2015-01-22/ {FN=FILENAME}
>     /NS Primary Error/{CNT++}
>     END{pa()}' '{}' '+'
awk: syntax error near line 2
awk: bailing out near line 2

Here is some output from a trace file to help better understand what is needed. Each block has a different time stamp and needs to be included in the count. Notice they are NOT on the same line.

Code:
*** 2015-01-03 15:00:18.382
error encountered when answering new connection:
  NS Primary Error: TNS-12560: TNS:protocol adapter error
  NT Generic Error: TNS-00530: Protocol adapter error
  Solaris Error: 130: Software caused connection abort
 
*** 2015-01-05 10:23:09.180
unexpected error 12560 for connection:
  NS Primary Error: TNS-12535: TNS:operation timed out
  NS Secondary Error: TNS-12560: TNS:protocol adapter error
  NT Generic Error: TNS-00505: Operation timed out


Thanks for looking at this for me.

regards

al

Last edited by rbatte1; 01-23-2015 at 08:38 AM.. Reason: Added CODE tags and corrected spelling and case
# 5  
Old 01-26-2015
Sorry about the delay getting back to you on this. Real world commitments and a Public holiday are to blame.

On Solaris try /usr/xpg4/bin/awk instead, which is POSIX awk (or nawk if that is not available).

Your demo input is interesting and raises a couple of further questions:

1) should the date "2015-02-22" and "NS Primary Error" both occur ANYWHERE in the file or within the same error block?

2) Is the format of these error blocks consistent i.e starting with "***" and a blank line between them?
# 6  
Old 01-26-2015
Hi

No rush we are all busy.

I wrote up a detail for ease of understanding. Sorry if it is long. See below:

My operating system is:

OPERATING SYSTEM:
uname -a
SunOS snslcsunu04 5.10 Generic_150400-13 sun4u sparc SUNW,SPARC-Enterprise

DESCRIPTION OF PROBLEM:

We have 5 servers the each have over a hundred oracle databases. The issue isn’t with the databases it is with the servers. We are getting a lot of dropped connections on the server but don’t know which databases are refusing connections. I need to design a metric that can track those databases via numbers as to which one is getting worse or better.

We need to analyze the trace files every day on the “TNS-12535: TNSSmilieperation timed out” for example for all the databases in the
/oracle/diag/rdbms/*/*/trace directory. Where the * is the name of the database twice for clarification.

Here is MY THINKING and what I got so far.

find /oracle/diag/rdbms/*/*/trace –type f -name '*d00*.trc' -mtime 0 -exec egrep -c 'TNS-12535: TNSSmilieperation timed out' '{}' '+'
OUTPUT:
/oracle/diag/rdbms/abcdef/abcdef/trace/abcdef_d001_21751.trc:11
/oracle/diag/rdbms/abcdef/abcdef/trace/abcdef_d000_21750.trc:27
/oracle/diag/rdbms/ghijkl/ghijkl/trace/ghijkl_d001_22002.trc:61
/oracle/diag/rdbms/ghijkl/ghijkl/trace/ghijkl_d000_22001.trc:57

GOAL: My final OUTPUT will be the same as above but with lesser numbers and/or lesser lines.

Now I need to go through these 4 above looking for the data in this case ‘2015-01-26’. First though I need to remove the excess information on the string the colon and the number . I do that by using awk. Here is my syntax:

find /oracle/diag/rdbms/*/*/trace -type f -name '*d00*.trc' -mtime 0 -exec egrep -c 'TNS-12535: TNSSmilieperation timed out' '{}' '+' | awk -F: '{print $1}'

OUTPUT: Notice there are no trailing : or numbers.

/oracle/diag/rdbms/musidp/musidp/trace/musidp_d001_21751.trc
/oracle/diag/rdbms/musidp/musidp/trace/musidp_d000_21750.trc
/oracle/diag/rdbms/musiop/musiop/trace/musiop_d001_22002.trc
/oracle/diag/rdbms/musiop/musiop/trace/musiop_d000_22001.trc

You would think that the following addition to the syntax would work
| egrep –c ‘{}’ ‘+’ would work returning some or all of the same output files as before but fewer numbers for example.

These numbers are what I am looking for. These represent all trace files for all databases for only today that had disconnects with different timestamps during that day.

Ex.

/oracle/diag/rdbms/abcdef/abcdef/trace/abcdef_d001_21751.trc:6
/oracle/diag/rdbms/abcdef/abcdef/trace/abcdef_d000_21750.trc:14
/oracle/diag/rdbms/ghijkl/ghijkl/trace/ghijkl_d001_22002.trc:25
/oracle/diag/rdbms/ghijkl/ghijkl/trace/ghijkl_d000_22001.trc:31

But it doesn’t. It produces the following:

find /oracle/diag/rdbms/*/*/trace -type f -name '*d00*.trc' -mtime 0 -exec egrep 'TNS-12535: TNSSmilieperation timed out' '{}' '+' | awk -F:| egrep -c '2015-01-26'

OUTPUT:
awk: syntax error near line 1
awk: bailing out near line 1
0

Can someone please suggest what I is written wrong in the syntax above or maybe an entirely another way of accomplishing this project?

It would be much appreciated.

Thanks in advance.
# 7  
Old 01-26-2015
Try this:

Code:
find /oracle/diag/rdbms/*/*/trace -type f -name '*d00*.trc' -mtime 0  -exec \
/usr/xpg4/bin/awk  '/NS Primary/ && /2015-01-03/ {F++} END{ if(F) print FILENAME":"F}' RS="" '{}' ';'

Replace /usr/xpg4/bin/awk marked in red above with, nawk if you get /usr/xpg4/bin/awk is not found errors.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare Date to today's date in shell script

Hi Community! Following on from this code in another thread: #!/bin/bash file_string=`/bin/cat date.txt | /usr/bin/awk '{print $5,$4,$7,$6,$8}'` file_date=`/bin/date -d "$file_string"` file_epoch=`/bin/date -d "$file_string" +%s` now_epoch=`/bin/date +%s` if then #let... (2 Replies)
Discussion started by: Greenage
2 Replies

2. UNIX for Beginners Questions & Answers

Find and copy .zip file based on today's date

Hi Team, I'm new to unix and i have a requirement to copy or move files from one directory to another based on current date mentioned in the .zip file name. Note that i need to copy only the recent zip file. please help me with the code i tried the code as: #! /usr/bin/sh find... (3 Replies)
Discussion started by: midhun3108
3 Replies

3. Shell Programming and Scripting

Check, if date is not today

hello, in a file exist entries in date format YYYYMMDD. i want to find out, if there are dates, which isn't today's date. file: date example text 20140714 <= not today's date 20140715 <= not today's date 20140716 <= today's date my idea is to use Perderabo's datecalc ... (2 Replies)
Discussion started by: bora99
2 Replies

4. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

5. Shell Programming and Scripting

Need to add a date column (today's date) in file

Hi I have file with number status and date1 and date1 field, want add a column today between column date1 and date2. file1.txt number status date1 date2 ===== ==== === ===== 34567 open 27/06/13 28/06/13 45678 open 27/06/13 28/06/13 43567 open 27/06/13 28/06/13 ... (1 Reply)
Discussion started by: vijay_rajni
1 Replies

6. Shell Programming and Scripting

UNIX date fuction - how to deduct days from today's date

Hi, One of my Unix scripts needs to look for files coming in on Fridays. This script runs on Mondays. $date +"%y%m%d" will give me today's date. How can I get previous Friday's date.. can I do "today's date minus 3 days" to get Friday's date? If not, then any other way?? Name of the files is... (4 Replies)
Discussion started by: juzz4fun
4 Replies

7. Shell Programming and Scripting

[Solved] Replace yesterday date with today's date except from the first line

Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use... (3 Replies)
Discussion started by: Lilu_CK
3 Replies

8. Shell Programming and Scripting

Find file that matches today's date in filename and move to /tmp in bash

I'm having problems with my bash script. I would like to find a file matching today's date in the filename, i.e. my_file_20120902.txt and then move it to a different directory, i.e. /tmp. Thanks. (1 Reply)
Discussion started by: jamesi
1 Replies

9. UNIX for Dummies Questions & Answers

Shell Scripts - shows today’s date and time in a better format than ‘date’ (Uses positional paramete

Hello, I am trying to show today's date and time in a better format than ‘date' (Using positional parameters). I found a command mktime and am wondering if this is the best command to use or will this also show me the time elapse since 1/30/70? Any help would be greatly appreciated, Thanks... (3 Replies)
Discussion started by: citizencro
3 Replies

10. UNIX for Dummies Questions & Answers

compare today's date with date in a file

Hi I am very new to scripting, Can someone show me how to (in unix shell script) compare the system's date with a date in a file. The requirement is to somehow open this file (which will only have a date in it) and compare it with today's date. If they are equal execute a procedure below but if... (4 Replies)
Discussion started by: siog
4 Replies
Login or Register to Ask a Question