Find the latest directory and loop through the files and pick the error messages
Hi,
I am new to unix and shell scripting,can anybody help me in sctipting a requirement.
my requirement is to get the latest directory the name of the directory will be like CSB.monthdate_time stamp
like CSB.Sep29_11:16 and CSB.Oct01_16:21.
i need to pick the latest directory.
in the directory there will be a 5 error files like
THerrFile_1.err
THerrFile_2.err
THerrFile_3.err
THerrFile_4.err
THerrFile_5.err.
I need to go thorugh each one of the file and pick the ORA- error codes and ora message from the file.
This thread is not connected to the AIX operating system. I am going to transfer it to the "Shell Programming and Scripting" board therefore.
Quote:
Originally Posted by sudhir_83k
Hi,
my requirement is to get the latest directory the name of the directory will be like CSB.monthdate_time stamp
like CSB.Sep29_11:16 and CSB.Oct01_16:21.
i need to pick the latest directory.
in the directory there will be a 5 error files like
I need to go thorugh each one of the file and pick the ORA- error codes and ora message from the file.
Please advice.
Actually these are three distinct problems:
1) Find the latest directory and get its name;
2) cycle through all the files of a directory with a given name.
3) pick the ORA-messages
2) and 3) are rather easy to accomplish as long as there is no subdirectory structure possible (like in your requirement). You can use the "ls"-command to cycle through all directory entries and pipe the output of it into a while-loop. There you can use "grep" on these files:
Run this little script and try to understand how it works. Concepts to grasp are: (1) pipelines and how they work; (2) variable expansion; (3) the "while...read"-loop in ksh.
Your first problem - finding the latest directory - is a little more tricky, depending on your situation: every directory entry (that includes directories) has a time stamp and you can tell the "ls"-command to sort the entries by that time stamp (instead of alphabetically, which is the default). It might be that you are looking for the directory with the latest time stamp and in this case you can use the output of "ls -t" and snip off the first line - it will contain the youngest directory entry:
If the directories you look at have to be sorted by their names and their time stamps do not correspond your task will be a bit more difficult. Write again in this case and i will show you a solution for this.
./ora_error.sh[5]: -ltrd: not found
./ora_error.sh[6]: a: not found
rm: oraerr_output.txt: No such file or directory
grep: can't open THerrFile_2.err
grep: can't open THerrFile_3.err
grep: can't open THerrFile_4.err
grep: can't open THerrFile_5.err
I am trying to fetch the latest modified file from a directory using the command
find . -type f -exec ls -lt \{\} \+ | head | awk '{print $9}'
After the O/P, I get the below mentioned error and the command doesnt terminate at all.
find: ls terminated by signal 13
find: ls terminated by... (2 Replies)
I wan to pick the latest modified file name and redirect it to a file ..
ls -tr | tail -1 >file
but this is printing file ins side the filename ,
can anyone help me out (5 Replies)
I have a few log files which get generated on a daily basis..So, I need to pick only the ones which get generated for that particular day.
-rw-r--r-- 1 staff 510732676 Apr 7 22:01 test.log040711
-rwxrwxrwx 1 staff 2147482545 Apr 7 21:30 test.log.2
-rwxrwxrwx 1 staff 2147482581 Apr 7 19:26... (43 Replies)
I want to get the latest files from multiple directories, d1, d2,d3 and d4 under the parent dierectoy d.
can anyone help out with this?
thx (3 Replies)
Hi,
I have some list of directories in the form datemonthyear e.g. 02082009, 03082009 and 04082009 etc.
I need to pick the latest directory from the current working directory.
Outcome:
05082009
This is the output am expecting.
Thanks (6 Replies)
in the below .. i want to pick the latest logfile which is having JPS.PR inside..
that means i want particularly "spgport040408041223.log:@@@@@@@@ 04:13:09 Adding: JPS.PR."
which is latest among these..
is it possible to compare the current time with logfile time ?
reptm@xblr0758rop>... (4 Replies)
I have task in which I need to pickup a set of files from a directory
depending on the following criteria:
Every month 6 files are expected to arrive at /test.
The files come with date timestamp and the latest file set for the month needs to be used
Suppose this is the set of files that present... (5 Replies)
i have a directory in which there are executable files and these files are added at runtime. now i need a shell script which will be called at a certain interval. this shell script should find the latest executable file in that directory and start that executable. care should be taken that once the... (6 Replies)