Check last lines of different files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check last lines of different files
# 1  
Old 11-07-2011
Check last lines of different files

Hey,

Each night, about 2000 network devices are being backupped. So in different folders, i've got each night 2000 new text files.
And normally, in these files, on the last 5 lines, the word 'end' or 'return' should be found. If not, it means that the backup failed.

Is there an easy way (script) to check the files if these words are on the last 5 lines?
A kind of output in a log file would be great...


Thanks!
# 2  
Old 11-07-2011
The tail command is your friend
Code:
$tail -f file1 file2 file3

Otherwise look for a tool named multitail to tail multiple files.
# 3  
Old 11-07-2011
Something like:
Code:
for file in *.txt
do
   tail -5 $file | grep -E "end|return" > /dev/null 2>&1
   if [ $? -ne 0 ]
   then
      echo $file failed
   fi
done

# 4  
Old 11-07-2011
Carlo,

This works perfect...



The end result:

Code:
 CURRENT_DATE=$(date '+%Y%m%d)

for file in /backups/*/$CURRENT_DATE/*.txt
do
   tail -5 $file | grep -E "end|return" > /dev/null 2>&1
   if [ $? -ne 0 ]    
   then
      echo $file failed >> /var/log/backups/checks/$CURRENT_DATE.log    
   fi
done

Maybe an extra check that i don't have to check manually the log files, but this helps me already a lot...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies

2. Shell Programming and Scripting

How to find files containing two specific lines and delate those lines?

Hi I need to find files in a specified folder where are two specified lines of text and delate that lines. It looks like this" 35. ?>NL 36. <iframe>.......</iframe>NLThe problem is that "?>" is in the other lines and id should not be removed if the next line is not like "<iframe>....." So... (4 Replies)
Discussion started by: androwida
4 Replies

3. Shell Programming and Scripting

Print n lines from top and n lines from bottom of all files with .log extenstion

Oracle Linux 6.4 In a directory I have more than 300 files with the extension .log I want the first 5 and last 5 lines of these .log files to be printed on screen with each file's name. Expected output : Printing first 5 and last 5 lines of FX_WT_Feb8_2014.log !! Authentication... (7 Replies)
Discussion started by: kraljic
7 Replies

4. UNIX for Advanced & Expert Users

SQL script with 86000 lines: new files with only 10000 lines (per file)

Hi this is my SQL script $ wc -l insert_into_customers.sql 85601 insert_into_customers.sqlI wish to cut this file into 9 files each 10000 lines (the last one less) $ wc -l insert_into_customers_00*.sql 10000 insert_into_customers_001.sql 10000 insert_into_customers_002.sql ... (1 Reply)
Discussion started by: slashdotweenie
1 Replies

5. Shell Programming and Scripting

Perl code to check date and check files in particular dir

Hi Experts, I am checking how to get day in Perl. If it is “Monday” I need to process…below is the pseudo code. Can you please prove the code for below condition. if (today=="Monday" ) { while (current_time LESS THAN 9:01 AM) ... (1 Reply)
Discussion started by: ajaypatil_am
1 Replies

6. UNIX for Dummies Questions & Answers

to check the latest lines of log in vi editor itself..

Hi Folks, If I open the logs in vi editor but as the logs get update after few seconds and I want to see the latest lines then whats the command to see the latest lines in vi editor itself , lets say I have open a log named abc.log in vi..!! vi abc.log (2 Replies)
Discussion started by: SankalpS
2 Replies

7. Shell Programming and Scripting

need a shell script to extract the files from source file and check whether those files existonserve

Hi, I am new to shell scripting.Please help me on this.I am using solaris 10 OS and shell i am using is # echo $0 -sh My requirement is i have source file say makefile.I need to extract files with extensions (.c |.cxx |.h |.hxx |.sc) from the makefile.after doing so i need to check whether... (13 Replies)
Discussion started by: muraliinfy04
13 Replies

8. Shell Programming and Scripting

merging two .txt files by alternating x lines from file 1 and y lines from file2

Hi everyone, I have two files (A and B) and want to combine them to one by always taking 10 rows from file A and subsequently 6 lines from file B. This process shall be repeated 40 times (file A = 400 lines; file B = 240 lines). Does anybody have an idea how to do that using perl, awk or sed?... (6 Replies)
Discussion started by: ink_LE
6 Replies

9. Shell Programming and Scripting

need to delete all lines from a group of files except the 1st 2 lines

Hello, I have a group of text files with many lines in each file. I need to delete all the lines in each and only leave 2 lines in each file. (3 Replies)
Discussion started by: script_op2a
3 Replies

10. Shell Programming and Scripting

Check for lines in a file.

I have been looking for a good method to do the following. I would like to check a file to verify two lines exist that start with yyy and verify other lines that start with yyy do not exist in file test1. If the other lines starting with yyy do exist I would like the script to echo “not remove” the... (3 Replies)
Discussion started by: elijah
3 Replies
Login or Register to Ask a Question