Monitoring log file for entries - Find command & sorting


 
Thread Tools Search this Thread
Operating Systems Solaris Monitoring log file for entries - Find command & sorting
# 1  
Old 08-28-2012
Monitoring log file for entries - Find command & sorting

hi,

I would like to monitor a log file, which rolls over, everytime a server is restarted.

I would like to grep for a string, and to be more efficient i'd like to grep only newly appended data. so something like a 'tail -f' would do, however, as the log rolls over i think a 'tail -F' is what i need, but this doesn't seem to be available in Solaris.

so any ideas welcome. the log file/s is named:

"test*.txt"

the string i'm looking for is "error_message_here"

so i was going to do something like this:

Code:
ls -lr|grep -i 'test.txt'|grep -i 'error_message'  # and i can then send this to email etc.

or should i use the find command, however, how would i then cat out the message.

so far i have:
Code:
find . -name 'test*.txt' | xargs ls -lr | head -1

output is this:

-rw-r--r-- 1 hrid hrinkp 601456524 Aug 22 09:06 ./test1.txt

so i find the files by name, then list/sort them with ls -lr, i then get the top entry (filename).......and that is the file that i'd like to grep/cat for the message.

how would i do that now? because i've used ls -l, its in long format, so i need to specify the coloumn which is the filename (./test1.txt) that I would like to search i.e.

thanks
# 2  
Old 08-28-2012
The first line puts a list of all test*txt files in reverse order into $1, $2, ... Note: you don't have to use -l, when you want files to be sorted in reverse order.
Code:
set -- $( ls -r test*.txt)

Now $1 holds the name of the file you want to grep. Now do it:
Code:
grep error_message $1 | mail ...

that seems to be all
This User Gave Thanks to hergp For This Post:
# 3  
Old 09-04-2012
thanks

Last edited by horhif; 09-04-2012 at 09:18 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Script to ZIP/SAVE & then DELETE Log file & send a mail conformation for any error

ENVIROMENT Linux: RHEL 6.4 Log Path: /usr/iplanet/servers/https-company/logs Log Format: user.log.03-15-2015 I have log4j log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I need a script that will run daily that... (1 Reply)
Discussion started by: admin_job_admin
1 Replies

2. Shell Programming and Scripting

How to find a file with a specific pattern for current sysdate & upon find email the details?

I need assistance with following requirement, I am new to Unix. I want to do the following task but stuck with file creation date(sysdate) Following is the requirement I need to create a script that will read the abc/xyz/klm folder and look for *.err files for that day’s date and then send an... (4 Replies)
Discussion started by: PreetArul
4 Replies

3. Shell Programming and Scripting

Recursive File Renaming & Natural Sorting (Bash)

NB! I have already started a thread on this subject on ComputerHope (with the thread title "Recursive File Renaming & Logical Sorting"). However, on ComputerHope they are perhaps more specialized in Windows Command Prompt, and not that much in shell scripts for Bash (I guess). I have a bulk... (1 Reply)
Discussion started by: JewzeyfGhewbelz
1 Replies

4. UNIX for Dummies Questions & Answers

Find & Replace command - Fasta file

Hi all ! I have a fasta file that looks like that: >Sequence1 RTYIPLCASQHKLCPITFLAVK (it's just an example, obviously in reality I have several pairs of lines like that) Using UNIX command(s), would it be possible to replace all the characters except the "C" of the second line only by... (7 Replies)
Discussion started by: Cevin21
7 Replies

5. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

6. Shell Programming and Scripting

faster command than find for sorting?

I'm sorting files from a source directory by size into 4 categories then copying them into 4 corresponding folders, just wondering if there's a faster/better/more_elegant way to do this: find /home/user/sourcefiles -type f -size -400000k -exec /bin/cp -uv {} /home/user/medfiles/ \; find... (0 Replies)
Discussion started by: unclecameron
0 Replies

7. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

8. UNIX for Dummies Questions & Answers

sorting files with find command before sending to text file

i need help with my script.... i am suppose to grab files within a certain date range now i have done that already using the touch and find command (found them in other threads) touch -d "$date_start" ./tmp1 touch -d "$date_end" ./tmp2 find "$data_location" -maxdepth 1 -newer ./tmp1 !... (6 Replies)
Discussion started by: deking
6 Replies

9. UNIX for Dummies Questions & Answers

Monitoring & emailing log files

Hi ..first post ! I have a Unix v445 using solaris 10. I've trolled through various web pages but can't find exactly what I'm looking for. I have an alert log...or any messages file for that matter I need to check for certain key (error type) phrases - if I find them, they are redirected to... (11 Replies)
Discussion started by: davidra
11 Replies
Login or Register to Ask a Question