Sponsored Content
Top Forums Shell Programming and Scripting Find and awk with today's date Post 302932950 by bdby on Monday 26th of January 2015 03:15:30 PM
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
nqs2pbs(1B)								PBS							       nqs2pbs(1B)

NAME
nqs2pbs - convert NQS job scripts to PBS SYNOPSIS
nqs2pbs nqs_script [pbs_script] DESCRIPTION
This utility converts a existing NQS job script to work with PBS and NQS. The existing script is copied and PBS directives, #PBS , are inserted prior to each NQS directive #QSUB or #@$ , in the original script. Certain NQS date specification and options are not supported by PBS. A warning message will be displayed indicating the problem and the line of the script on which it occurred. If any unrecognizable NQS directives are encountered, an error message is displayed. The new PBS script will be deleted if any errors occur. OPERANDS
nqs_script Specifies the file name of the NQS script to convert. This file is not changed. pbs_script If specified, it is the name of the new PBS script. If not specified, the new file name is nqs_script.new . NOTES
Converting NQS date specifications to the PBS form may result in a warning message and an incompleted converted date. PBS does not support date specifications of "today", "tomorrow", or the name of the days of the week such as "Monday". If any of these are encountered in a script, the PBS specification will contain only the time portion of the NQS specification, i.e. #PBS -a hhmm[.ss]. It is suggested that you specify the execution time on the qsub command line rather than in the script. Note that PBS will interpret a time specification without a date in the following way: - If the time specified has not yet been reached, the job will become eligible to run at that time today. - If the specified time has already passed when the job is submitted, the job will become eligible to run at that time tomorrow. PBS does not support time zone identifiers. All times are taken as local time. SEE ALSO
qsub(1B) Local nqs2pbs(1B)
All times are GMT -4. The time now is 02:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy