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.
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
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?