Find the latest directory and loop through the files and pick the error messages


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find the latest directory and loop through the files and pick the error messages
# 8  
Old 10-11-2010
hi Guy's

Thanks for the help.
i changed the code accordingly.
but i am facing the below error message.

Code:
>./ora_error.sh
./ora_error.sh[6]: cd: bad argument count
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


Last edited by Scott; 10-12-2010 at 09:23 AM.. Reason: Code tags
# 9  
Old 10-11-2010
There are quite a few reasons to those errors..

Quote:
./ora_error.sh[6]: cd: bad argument count
1.The value of the variable a holds something like
Quote:
-rw-r--r-- 1 ondesk staging 155 Oct 8 03:17 some.txt
. So when u try to change directory (cd $a) the shell will be unable to do so and throws the above error.Hence try to give the correct directory name to cd
2.Also make sure the argument to cd is given as absolute path (if changing to different directory)

Quote:
grep: can't open THerrFile_2.err
Make sure above such file exist in the current working dir. i.e where you have saved/run this shell script.Else specify the correct path.
# 10  
Old 10-11-2010
Thanks Micheal.

How can we tuncate the information i.e

drwxrwsr-x 2 tia uniqgrp 12288 10 Oct 00:30 CSB.Oct10_00:01/

i need to get only the directory name i.e CSB.Oct10_00:01 part
but not the entire line.

please advice.

---------- Post updated at 09:55 AM ---------- Previous update was at 08:38 AM ----------

Hi,

Code:
 
#catr.ksh
#!/bin/ksh

v=""
a='ls -ltrd CSB.*|tail -1|egrep -v '^CSB.*'|awk '{ print$9 }''
cd $a
rm oraerr_output.txt
for j in 1 2 3 4 5
do
v="THerrFile_$j.err";
grep -i "$j:Error" $v >>oraerr_output$j.txt
cat oraerr_output$j.txt >> oraerr_output.txt
rm oraerr_output$j.txt
done

in the above code for variable a i am getting a directory name.
but in "Cd $a" it is not going into the directory.

because i am getting the below errors.

}
grep: can't open THerrFile_1.err
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

Please advice if the above code is correct or i am going wrong some where.
# 11  
Old 10-12-2010
1.It wud have been better if you have posted the value of a. Looking the above code seems like var a is not executed.Try as below as prev said..

Code:
a=$(ls -ltrd CSB.*|tail -1|egrep -v '^CSB.*'|awk '{ print$9 }')

Do not use those single quotes- ' '

2. Before grep'ing the file THerrFile_*.err take sometime to check if that file exist in your current working dir or where this script is stored.As the error states
Quote:
grep: can't open THerrFile_1.err
- there is no such file in the current dir.
This User Gave Thanks to michaelrozar17 For This Post:
# 12  
Old 10-12-2010
Quote:
Originally Posted by sudhir_83k
How can we tuncate the information i.e

[code]drwxrwsr-x 2 tia uniqgrp 12288 10 Oct 00:30 CSB.Oct10_00:01/[code]

i need to get only the directory name i.e CSB.Oct10_00:01 part
Just omit the "-l" switch from the "ls"-command. Instead of "ls -ltrd ...." use "ls -trd ...."

I hope this helps.

bakunin
# 13  
Old 10-12-2010
Hi,

Thanks Micheal,

For the point-2:

once the cd command is executed then i can grep the files in the directory.As the directory is not changing i am not able to grep and it says can't open the THerrFile_2.err file.

the value of a will be like CSB.Oct11_17:30.

it is not working .

please help.



-------

It is working fine now.
I am copying the final code.hope it may help some one.

Code:
#catr.ksh
#!/bin/ksh
 
v=""
a=$(ls -ltrd CSB.*|tail -1|egrep -v '^CSB.*'|awk '{ print$9 }')
cd $a
rm oraerr_output.txt
for j in 1 2 3 4 5
        do
                v="THerrFile_$j.err";
                grep -i "$j:Error" $v >>oraerr_output$j.txt
                cat oraerr_output$j.txt >> oraerr_output.txt
                rm oraerr_output$j.txt
done

Thanks guys for your help.

Moderator's Comments:
Mod Comment Use code tags. Thank you.

Last edited by Scott; 10-12-2010 at 09:24 AM..
# 14  
Old 10-22-2010
It is comming out when we donot find a file

Hi,

the code that i pasted in my previous posts works fine ,if all files are existing.if any file is missing it is comming out.

but my requirement is,it should go to next file and grep the ora-messages.
i am copying my code also.

for example if we couldn't find THerrFile_1.err file in the directory.it is comming out,it should go to
THerrFile_2.err ,THerrFile_3.err ,THerrFile_4.err ,THerrFile_5.err files and pick the ora-messages.


please advice.

Code:
 
#catr.ksh
#!/bin/ksh

v=""
a=$(ls -ltrd CSB.*|tail -1|egrep -v '^CSB.*'|awk '{ print$9 }')
cd $a
rm oraerr_output.txt
for j in 1 2 3 4 5
do
v="THerrFile_$j.err";
grep -i "$j:Error" $v >>oraerr_output$j.txt
cat oraerr_output$j.txt >> oraerr_output.txt
rm oraerr_output$j.txt
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I have this list of files . Now I will have to pick the latest file based on some condition

3679 Jul 21 23:59 belk_rpo_error_**po9324892**_07212014.log 0 Jul 22 23:59 belk_rpo_error_**po9324892**_07222014.log 3679 Jul 23 23:59 belk_rpo_error_**po9324892**_07232014.log 22 Jul 22 06:30 belk_rpo_error_**po9324267**_07012014.log 0 Jul 20 05:50... (5 Replies)
Discussion started by: LoneRanger
5 Replies

2. Shell Programming and Scripting

Code to pick all files from a directory and send it to a command

(4 Replies)
Discussion started by: rossi
4 Replies

3. UNIX for Dummies Questions & Answers

To find the latest modified file in a directory

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)
Discussion started by: Sree10
2 Replies

4. Shell Programming and Scripting

to pick the latest file modified in a directory

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)
Discussion started by: vishwakar
5 Replies

5. UNIX for Dummies Questions & Answers

How to pick only the latest files based on the timestamp?

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)
Discussion started by: win4luv
43 Replies

6. Shell Programming and Scripting

find the latest files in multiple directory

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)
Discussion started by: shyork2001
3 Replies

7. UNIX for Dummies Questions & Answers

pick the very latest directory

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)
Discussion started by: venkatesht
6 Replies

8. Shell Programming and Scripting

how can i pick the latest log file as per below

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)
Discussion started by: mail2sant
4 Replies

9. Shell Programming and Scripting

Pick the latest set of files

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)
Discussion started by: w020637
5 Replies

10. Shell Programming and Scripting

script to find latest executable in particular directory and start that particular ex

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)
Discussion started by: kvineeth
6 Replies
Login or Register to Ask a Question