File Search


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Search
# 1  
Old 10-24-2003
Java File Search

I hope I can outline this clearly the first time. I have been asked to create a script to do the following:

Search a series of Directories that have been created withing 15 minutes of the current system time for a dynamic file name that ends in (dot)out .out.
If a file with that extension is found, search the file for the word "error".
If error is found, send an email to a data center operator.
If the word is NOT found, do nothing.

I believe I can handle items 3 and 4, but I am looking for help and suggestions in accomplishing item 1.
Thanks in Advance.
# 2  
Old 10-24-2003
hmm.....

that's looking like your homeexercise!

https://www.unix.com/post-here-to-contact-site-administrators-and-moderators/3522-homework-issues.html?s=

# man find
# man fgrep
# man mail
# man if

preßy
# 3  
Old 10-24-2003
I don't agree that this sounds like homework. But I don't have enough information to help. Do you need to search the entire filesystem looking for recently created directories?
# 4  
Old 10-25-2003
One could do this in php:
PHP Code:
$path "{whatever the path should be...}";
exec("slocate | grep $path | grep \".out\""$results);

foreach(
$results as $file)
{
 if(
filectime($file => (time() - 900)))
 {
    
$fp fopen($file);
    
$test fgets($file);
    if(
gettype(ereg("error"$test)) != boolean)
      
mail({do your thing...});
 }

erm... i forget if time() returns the epoch time stamp or not, but meh.
# 5  
Old 10-27-2003
Thanks for the comments. First, this is NOT a homework exercise. Second I need to search for newly created directories below a specific path. This is a People Soft installation, and we are trying to automate the PI Run monitoring process.
Third, I am a novice Shell programmer, and know nothing about php. I have been trying to do this in a straight shell script because I think it makes better sense, but I am getting things out of syntax or something. Here's is what I have tried thus far.
###################################
find /opt/psoft/hr83tst/appserv/prcs/HRTST/log_output/AE_PI_* \
-type f \
-name '*.out' \
-exec grep -s error {} |mail -s"PI RUN Process Error" mikev@beverlycorp.com ';'\
-exec ls -ld {} ';'
###################################
Any suggestions?
Thanks in advance.
# 6  
Old 10-27-2003
If you really mean what you said this is going to be very hard. Unix does not record creation time. What if a *.err suddenly appears in a directory that is one hour old? Is it really necessary to exclude it? If so, you need to create a list of pre-existing directories and test each candidate directory to see if it's on that list. And that list must have been prepared 15 minutes ago to satify your time requirement.

If you're willing tolerate being notified about newly arrived *.err files in old directories, you still have a similiar problem... no creation date. So you can't distinguish between a file that was created recently and one that was updated recently.

And your find statement does not seem to be worrying about these issues. Could it be a list of *.err files that recently had a write() is good enough?
# 7  
Old 10-27-2003
Yes I am serious about the search. However, the directories needing searched are created each time the process runs success or failure. if I backup to the 'log_output' directory, the script above returns the expected results, but errors out when trying to send mail. The file name being sought in each sub-dir ends with 'out', if it contains the word 'error' the process was a failure. All other successful processes will NOT contain the word 'error'.

The email and some type of creation time for new directories/files is the issue with the above script/

You obviously know what you are talking about, so if you have any suggestions on how I might proceed, I would GREATLY appreciate it.
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run a loop that will search for a file to thousand machine and know who owns the file

Run a loop that will search for a file to thousand machine and know who owns the file $ for i in abc{01..02} > do > echo -n $i > ssh $i "sudo find / -name .ssh -exec ls -l {} \;|grep id" > done abc01-rw-------. 1 root root 1675 Nov 10 2018 id_rsa abc01-rw-------. 1 root root 1675 Nov 14... (6 Replies)
Discussion started by: invinzin21
6 Replies

2. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

3. UNIX for Dummies Questions & Answers

Search file and print everything except multiple search terms

I'm trying to find a way to search a range of similar words in a file. I tried using sed but can't get it right:sed 's/\(ca01\)*//'It only removes "ca01" but leaves the rest of the word. I still want the rest of the information on the lines just not these specific words listed below. Any... (3 Replies)
Discussion started by: seekryts15
3 Replies

4. Shell Programming and Scripting

Retrieving the relevant search from search file in the main file

I have two files: file 1: hello.com neo.com,japan.com,example.com news.net xyz.com, telecom.net, highlands.net, software.com example2.com earth.net, abc.gov.uk file 2: neo.com example.com abc.gov.uk file 2 are the search keys to search in file 1 if any of the search... (7 Replies)
Discussion started by: csim_mohan
7 Replies

5. Shell Programming and Scripting

Nested search in a file and replace the inner search

Hi Team, I am new to unix, please help me in this. I have a file named properties. The content of the file is : ##Mobile props east.url=https://qa.east.corp.com/prop/end west.url=https://qa.west.corp.com/prop/end south.url=https://qa.south.corp.com/prop/end... (2 Replies)
Discussion started by: tolearn
2 Replies

6. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

7. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

8. Shell Programming and Scripting

Optimised way for search & replace a value on one line in a very huge file (File Size is 24 GB).

Hi Experts, I had to edit (a particular value) in header line of a very huge file so for that i wanted to search & replace a particular value on a file which was of 24 GB in Size. I managed to do it but it took long time to complete. Can anyone please tell me how can we do it in a optimised... (7 Replies)
Discussion started by: manishkomar007
7 Replies

9. Shell Programming and Scripting

sed help - search/copy from one file and search/paste to another

I am a newbie and would like some help with the following - Trying to search fileA for a string similar to - AS11000022010 30.4 31.7 43.7 53.8 60.5 71.1 75.2 74.7 66.9 56.6 42.7 32.5 53.3 I then want to replace that string with a string from fileB - ... (5 Replies)
Discussion started by: ncwxpanther
5 Replies

10. Shell Programming and Scripting

Read a file and search a value in another file create third file using AWK

Hi, I have two files with the format shown below. I need to read first field(value before comma) from file 1 and search for a record in file 2 that has the same value in the field "KEY=" and write the complete record of file 2 with corresponding field 2 of the first file in to result file. ... (11 Replies)
Discussion started by: King Kalyan
11 Replies
Login or Register to Ask a Question