![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl script to scan back lines | gholdbhurg | Shell Programming and Scripting | 3 | 03-18-2008 12:33 PM |
| File Inventory Scan | seacros | Shell Programming and Scripting | 4 | 03-17-2008 11:13 AM |
| File Scan | Dastard | Shell Programming and Scripting | 2 | 04-08-2007 03:35 PM |
| How Can I Easily Determine If A File Has been Added to a Directory | goodmis | UNIX for Advanced & Expert Users | 7 | 02-04-2007 01:13 AM |
| How Can I Easily Determine If A File Has been Added to a Directory | goodmis | UNIX for Dummies Questions & Answers | 1 | 01-31-2007 06:56 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to scan only new lines added in file?
Hi,
I am planning to implement a scheduled script that will go against my log files (every hour), search for a set of key words (errors, exceptions, faults etc). The script must be intelligent enough to scan only the new lines added to the log file since it last ran. I can use grep for searching, how can I scan only new lines added to the log file since it last ran? Any idea? any sample script? |
|
|||||
|
Searching thru only new lines add
Here is the trick I think (Moderators please advise).
Use diff. Suppose u r having file1 and file2. file2 is new and u want to search for occurence of LOTUS and red in new lines added in file2. U can do this: diff file1 file2 >> diff12 egrep 'LOTUS|red' diff12 This will work for single file. If u have many files...U will have to right a shell script.. It will hae somewhat following structure.. (I have written algorithm so it won't be syntactically correct) DO WHILE END OF NUMBER OF FILES. integer i string name name = 'difffile' & string(i) & 'diff' --> if i = 4 then name = difffile4.diff diff folder1/file1 folder2/file2 >> file2/name.diff LOOP this will give u a set of files with diferences in set of log files with only new lines. (I am assuming that existing entries in a log file won't get updated or changed. E.g. if file1 contains line 1 as 'REDANDGREEN' then file 2 will contain line1 as REDANDGREEN and not REDANDORANGE. If the existing entries are going to get updated then u may need to process the files with differences again to keep only new line differences. Try out DIFF and try to investigate more.) U can then fire a grep on these files with differences. Let me know ur comments.. Thank VEN |
|
|||||
|
I have used the same solution as forwarded by RTM and it works very well that way ... the only thing is you might want to make sure your filecounter file is not in /tmp just in case of an unplanned reboot --- i put mine in /var/tmp which is not a volatile directory in my solaris setup ...
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|