how to check if a new line has been added to a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to check if a new line has been added to a file?
# 1  
Old 03-26-2009
how to check if a new line has been added to a file?

Have come up with the following but it doesn't seem to work.. Is there some other command i could use to get this to work?

Code:
OUTPATH=/home/out
PARMFILE=$OUTPATH/jobcount_test.txt
LOG=$OUTPATH/job_count_monthlymail_log.txt
HLOG=$OUTPATH/job_count_monthlymail_hlog.txt
#
echo " started at $(date)" > $LOG
#
integer count=0
while [[ $count < 2 ]]
do
   body_msg=`tail -1 $PARMFILE`
   mailx -s "$body_msg" jarrathy@notes < $body_msg
   ((count = count +1))

done
##
echo " ended at $(date)" >> $LOG
cat $LOG >> $HLOG

I was updating the jobcount_test.txt and was hoping when i entered in a new line that the script would mail out that line and that when I had two lines in there the job would stop but it didn't.. can someone tell me what i'm doing wrong?
# 2  
Old 03-26-2009
Hi,
i m not sure exactly what you want..suppose if you want to know only when there is new line comes in your log ...then below will work...

i did small change in your script..

Code:
OUTPATH=/home/out
PARMFILE=$OUTPATH/jobcount_test.txt
LOG=$OUTPATH/job_count_monthlymail_log.txt
HLOG=$OUTPATH/job_count_monthlymail_hlog.txt
#
echo " started at $(date)" > $LOG
#
Linecount=`wc -l $PARMFILE|awk '{print $2}'`

while [[ $Linecount -le 2 ]]
do
   body_msg=`tail -1 $PARMFILE`
   mailx -s "$body_msg" jarrathy@notes < $body_msg
done
##
echo " ended at $(date)" >> $LOG
cat $LOG >> $HLOG

Thanks
SHa

Last edited by Franklin52; 03-26-2009 at 08:34 AM.. Reason: adding code tags
# 3  
Old 03-26-2009
Completely forgot about line counts... Thanks for that..

trying to set up a script that will keep running until a certain amount of lines are expected in the file, while also emailing out each new line that comes into that file

Tried what you suggested.. My while loop didn't like -le so changed it to < (using ksh so not sure if thats why -le didn't work)
Ran the script again and it didn't work.. Loop didn't exit out when i put two lines into the file.

Not sure where to go from here

Last edited by Jazmania; 03-26-2009 at 09:12 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Check for empty line at end of a dynamic header in each file

Hi Folks, I have a requirement to develop a shell script. PFB my requirement, Requirement: I need to check an empty line after the end of each header in respective file and if a empty line is present simply echo file OK and if empty line is not present echo "Adding empty line" and add an... (6 Replies)
Discussion started by: tpk
6 Replies

2. Shell Programming and Scripting

Execution problems when added two same content in each line

Input: >sample_1 ASDAFDGSGH >sample_2 ASDFDAFDSFS >sample_3 ASDAFDAFDFD >sample_4 ASDFDFDSFDSF . Desired output >sample_1 ASDAFDGSGHXX >sample_2 ASDFDAFDSFSXX >sample_3 ASDAFDAFDFDXX (2 Replies)
Discussion started by: patrick87
2 Replies

3. Shell Programming and Scripting

Need to echo a text where a (.) is added to the end of line during on-going copy or ftp

Hello All, I would like to create a script to echo a text where a (.) dot is added every 2 seconds to the end of this text (with a limit of 10 dots) as long as a file copy or ftp is ongoing and once the copy is finished it adds "done" to the end of this text line. please see the below example: ... (6 Replies)
Discussion started by: Dendany83
6 Replies

4. Shell Programming and Scripting

Added new line before a specific pattern problem asking

Input file: Sample1 Type pattern 842 3150 Sample1 Type range 842 3150 Sample1 Type pattern 842 1127 Sample1 Type option 842 1127 Sample1 Type length 1483 1603 Sample1 Type pattern 1483 1603 Sample1 Type length 1698 1747 Sample1 Type option 1698 1747 Sample1 Type length 1868 1935 Sample1... (13 Replies)
Discussion started by: patrick87
13 Replies

5. Shell Programming and Scripting

How to check for a character at last line of the file?

this is the csv file. i want to check the last line contains the character N. Record Type#Batch Job ID#Batch Number#FileCreation Date#FileCreation Time#Production/Test Fileindicator#File Character H#0002#0002#20100218#17.25#P#barani Record Type#A#B#C#D#E#F#G#H#J#K#L... (5 Replies)
Discussion started by: barani75
5 Replies

6. Shell Programming and Scripting

one line command to check file existence and FTP it

Hi all, I need a batch script to Check for existence of file say i check for files with extension xml.done in C:\Myfile.(This folder contains .xml file and its corresponding .done files) If the .done file exists then it should FTP the corresponding .xml file to UNIX. Is this possible to do... (6 Replies)
Discussion started by: Codesearcher
6 Replies

7. Shell Programming and Scripting

check line by line in a file

Hi there How can I check line by line in a file? I need to compare the first value with the second to know if they are equal. If those values are equal, I require to send "TRUE" to the output or "FALSE" otherwise until the complete file has been read. Thank you (6 Replies)
Discussion started by: loperam
6 Replies

8. Shell Programming and Scripting

Read last line of file to check for value

Folks How best to read the last line of a file, to check for a particular value? This is the last line of my file...... 00000870000002000008 0000000020000 ......I need to check that this line contains '70' in positions 7 and 8, before I continue processing. Regards ... Dave (12 Replies)
Discussion started by: daveaasmith
12 Replies

9. UNIX for Dummies Questions & Answers

extran NUll character added after end of line "\n"

Hi All, I am facing a strange situation and want to find why it is occuring . When i convert the whole line into Hexadecimal character i can find the junk value after new line (\n) . If i look in binary mode it is not visible. PLease let me know how possible the junk character is added... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

10. Shell Programming and Scripting

check line in a file

Hi all, How do we check in a file whether a line started with KEYWORD2 is right after the line started with KEYWORD1 for example, this file content: Abcdef gsh iasdi 94945 9085095 lksdjlkj KEYWORD1 skljfi slakjfoi ' opiport sdfl KEYWORD2 ksjflsk jfasope jkdfsk393 89374982 23 ... (3 Replies)
Discussion started by: fongthai
3 Replies
Login or Register to Ask a Question