Mailing script using loops


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mailing script using loops
# 1  
Old 03-25-2009
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 05:16 AM..
# 2  
Old 03-25-2009
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  
Old 03-25-2009
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 05:14 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looking to minimize 'for' loops in script

Hi, Below is the script that I came up with but looking to see if there is a more appropriate way to achieve this by reducing number of "for" loops or something. Regards, mbak #!/usr/bin/ksh status=missing for disk in `lspv | awk '{print $1}'` do MISSPATH=`lspath -l ${disk} -s... (3 Replies)
Discussion started by: mbak
3 Replies

2. Shell Programming and Scripting

Two for loops in ksh script only one not executing

Hello, I have two "for loops" in my script and the second one is not executing the way i want. Script: #!/bin/ksh IFS=' ' printf "Enter Account name: " read A B C D E F G H I J K L M N O for i in ${A} ${B} ${C} ${D} ${E} ${F} ${G} ${H} ${I} ${J} ${K} ${L} ${M} ${N} ${O};... (3 Replies)
Discussion started by: seekryts15
3 Replies

3. Shell Programming and Scripting

Script loops again and again and again and ...

Hi, Linux newbie here with what I'm guessing is silly questions. My script below is working in that it correctly copies files from the backup IP (10.0.91.1) back down to the Linux server but trouble is it loops continuously. It correctly downloads 100 files from the the IP 10.0.91.1... (1 Reply)
Discussion started by: MOWS
1 Replies

4. Shell Programming and Scripting

mailing script not working

My mailing script #!/usr/bin/ksh SUBJECT="SETEMAILSUBJECT" MAIL="abc@xyz.com" MESSAGE="mail.txt" mail -s $SUBJECT $MAIL < $MESSAGE The script works fine in one server but not in another. Iam not getting any errors also in the second server. Also if i simply try echo testBody | mail... (1 Reply)
Discussion started by: blackhorse
1 Replies

5. Shell Programming and Scripting

Mailing Script

Hi, I am totally New to This Scripting Area.We have developed some reports in Bo and User need those reports to be sent through Unix Server (SFTP). Can any one provide me script for transfering File from one location to other with the requirement like if that file fails to reach destination... (4 Replies)
Discussion started by: Sashanth_S
4 Replies

6. Shell Programming and Scripting

Want to write a script for mailing line count

Hi all, I have a directory in which files are formed daily at certain time.files have certain naming convention for ex .. File1TTT.DATddmmyyyyhrsminsec File2TTT.DATddmmyyyyhrsminsec I want to take their line count when they are formed and mail that line count. Please help how to... (2 Replies)
Discussion started by: ammbhhar
2 Replies

7. Shell Programming and Scripting

Challenging task : script for mailing process completion timing report to users.

Hi all, This is my first post. I am new to unix scripting. My requirement is as follows : We are using a financial backoffice application. Now at the end of day we have send users a status report stating all timings of EOD processes for all countries. I need timings for following... (0 Replies)
Discussion started by: ammbhhar
0 Replies

8. Shell Programming and Scripting

Mailing script

Hi, I have a file lets say FILE1. FILE1 ------ name,age charlie,25 harry,29 david,32 Pls help me writing a mailing script.... which will mail the content of file in the body of the mail & it will look something like below in two columns. name age charlie 25 harry 29... (1 Reply)
Discussion started by: 46019
1 Replies

9. Shell Programming and Scripting

mailing from a shell script

Hi, This is what my script looks like: cd /var/apache/htdocs/MyApp var=`more /var/apache/htdocs/MyApp/activate` mailx -s "from MyApp" selma@mail.com <<EOT intro: -------------- $var EOT I get output that I would like to see when I invoke the script manually, this is is the... (2 Replies)
Discussion started by: Selma
2 Replies

10. UNIX for Advanced & Expert Users

Mailing thru UNIX shell script

Hi, I need to send an email from an UNIX shell script along with an attachment. I am working on an HP-UX 11.00 system. The only mailing program which provides adding an attachment to a mail is "pine". However pine is not installed on my system and I cannot install it too due to the server being a... (2 Replies)
Discussion started by: navin
2 Replies
Login or Register to Ask a Question