The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Enhancing Script (using loops) to go through for each group dolo21taf Shell Programming and Scripting 0 05-01-2008 12:12 AM
Mailing Problem nimish Shell Programming and Scripting 2 12-02-2005 11:38 PM
mailing from a shell script Selma Shell Programming and Scripting 2 05-17-2005 04:23 AM
Mailing an attachment gayath3 Shell Programming and Scripting 0 03-18-2005 06:09 AM
Mailing thru UNIX shell script navin UNIX for Advanced & Expert Users 2 08-10-2002 10:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-25-2009
Jazmania Jazmania is offline
Registered User
  
 

Join Date: Feb 2007
Location: Ireland
Posts: 43
How to check if a new line has been added to a file

Hi all..

I'm not a scripter but I'm trying to set up a mail script that emails out once a file has been written to.
Is there some way of writing a while read loop or something, so that it reads each line of the file and then ends when a specific number of lines have been written...

We're going to have 10 or 20 scripts that write to the file saying
script_1 started at $(date)
script_2 started at $(date)
script_1 ended at $(date)
and so on..

I don't know whether I should put some sort of trigger in the file to indicate that its the end of the file or because i know how many lines will be there just to put some sort of counter in the loop.

Edit: Using .ksh

Last edited by Jazmania; 03-26-2009 at 04:16 AM..
  #2 (permalink)  
Old 03-25-2009
samnyc samnyc is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 52
Here you can try this...



DATE=`/bin/date '+%m%d%y'`
MESSAGE="Found Error on XYZ "
MAILTO="A-team"
cd /home/alert
errfile="/home/alert/alert.2b.txt"
if [[ -e ${errfile} ]] ; then
cat $errfile | mailx -s "$MESSAGE" $MAILTO
fi
mv /home/alert/alert.2b.txt /home/alert/alert.2b.txt_$DATE
  #3 (permalink)  
Old 03-25-2009
Jazmania Jazmania is offline
Registered User
  
 

Join Date: Feb 2007
Location: Ireland
Posts: 43
How to check if a new line has been added to a file?

Ok your code works but its not exatly what I'm lookin for.. What the script to continuously look in the file and email out when a new line has been found.. the script will then email out the first word of the new line

I've tried to to it this way but no luck

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 had two lines in there the job would stop but it didn't.. can someone tell me what i'm doing wrong?

Last edited by Jazmania; 03-26-2009 at 04:14 AM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0