Mail text appending to previous mail text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mail text appending to previous mail text
# 1  
Old 02-23-2011
Mail text appending to previous mail text

The following is an extract of code I wrote to produce an email report of accounts that are about to expire.

It works fine except each time I run it the output is appended to all text from the previous mail that was sent. Can anybody see what I'm doing wrong?

Code:
paexpire=`sqlplus -s m@MAT/$PASS << EOF
set heading off feedback off verify off
SELECT USER_ID FROM m.user_hdr WHERE to_char(EXPIRE_ON, 'MM') = To_Char(SYSDATE, 'MM') +1 AND to_char(EXPIRE_ON, 'YY') = To_Char(SYSDATE, 'YY');
exit
EOF`

       echo "Team," | tee -a PAEXP
       echo "" | tee -a PAEXP
       echo "The following PA accounts will expire soon:" | tee -a PAEXP
       echo $paexpire | tee -a PAEXP
       echo "" | tee -a PAEXP
       echo "=====" | tee -a PAEXP
       echo "" | tee -a PAEXP


recexpire=`sqlplus -s tpa@MAT/$PASS2 << EOF
set heading off feedback off verify off
SELECT USER_ID FROM tpa.usrr WHERE to_char(NEXT_CHANGE_DT, 'MM') = To_Char(SYSDATE, 'MM') +1 AND to_char(NEXT_CHANGE_DT, 'YY') = To_Char(SYSDATE, 'YY');
exit
EOF`


       echo "The following RECS accounts will expire soon:" | tee -a PAEXP
       echo $recexpire | tee -a PAEXP
       echo "" | tee -a PAEXP
       echo "Regards" | tee -a PAEXP
       echo "MOTO Support" | tee -a PAEXP

mailx -s "MAT Expiring Accounts" email@me.com < PAEXP

exit

Regards
Paul
# 2  
Old 02-23-2011
Without checking your code exactly, you could just empty that file PAEXP with something like > PAEXP or just delete it after each succesful mailing? All those tee -a .. just append and append, but there seems to be no cleanup.
This User Gave Thanks to zaxxon For This Post:
# 3  
Old 02-23-2011
Cheers zaxxon. That pointed me in the correct direction. Changed my script to the following and no get the results I wanted:

Code:
paexpire=`sqlplus -s m@MAT/$PASS << EOF
set heading off feedback off verify off
SELECT USER_ID FROM m.user_hdr WHERE to_char(EXPIRE_ON, 'MM') = To_Char(SYSDATE, 'MM') +1 AND to_char(EXPIRE_ON, 'YY') = To_Char(SYSDATE, 'YY');
exit
EOF`
log=/var/opt/moto/logs/scripts/expiring_accounts.log

       echo "Team," | tee -a $log
       echo "" | tee -a $log
       echo "The following PA accounts will expire soon:" | tee -a $log
       echo $paexpire | tee -a $log
       echo "" | tee -a $log
       echo "=====" | tee -a $log
       echo "" | tee -a $log


recexpire=`sqlplus -s tpa@MAT/$PASS2 << EOF
set heading off feedback off verify off
SELECT USER_ID FROM tpa.usrr WHERE to_char(NEXT_CHANGE_DT, 'MM') = To_Char(SYSDATE, 'MM') +1 AND to_char(NEXT_CHANGE_DT, 'YY') = To_Char(SYSDATE, 'YY');
exit
EOF`


       echo "The following RECS accounts will expire soon:" | tee -a $log
       echo $recexpire | tee -a $log
       echo "" | tee -a $log
       echo "Regards" | tee -a $log
       echo "MOTO Support" | tee -a $log

mailx -s "MAT Expiring Accounts" email@me.com < $log

exit

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format text in mail attachments

Hi Gurus, I am working on a script that sends a text file attachment on mail from unix server to my widows outlook mail box. When i see the text file in UNIX it is perfectly formatted but when i open the same file in the mail, it looks weird as the next line is added to the same line. For... (10 Replies)
Discussion started by: jayadanabalan
10 Replies

2. Shell Programming and Scripting

send text mail to windows

Hi I have the following 'atd' batch script to send mail to a windows (outlook) system: .... .... LESSOPEN=\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN G_BROKEN_FILENAMES=1; export G_BROKEN_FILENAMES cd /root/bin || { echo 'Execution directory inaccessible' >&2 exit 1 }... (3 Replies)
Discussion started by: AdminLew
3 Replies

3. Shell Programming and Scripting

How to send colorful text and attachment to mail

Hi, I want to send color text as body of mail with multiple attachments.How to do this?I used sendmailcommand but this command fails for multiple attachments.Give me some solution on this. :wall: (0 Replies)
Discussion started by: AhmedLakadkutta
0 Replies

4. AIX

How to color text and mail

I want to color the text and bold the text and mail these text. input: hi..(in bold) good morning (in blue color) and mail these as in color and bold :wall: (1 Reply)
Discussion started by: AhmedLakadkutta
1 Replies

5. Shell Programming and Scripting

mail: subject and body text

HI, After giving the mail -e name@domain.com its asking the subject : after this its enter in to the body of the mail i.e. (in edit mode) How to end this edit process to send mail ? (2 Replies)
Discussion started by: thelakbe
2 Replies

6. UNIX for Dummies Questions & Answers

recover smtp mail text files

Hi All I was wondering if anyone knows how to recover smtp mail text files back into a mail client. I only have the smtp mail text files (eg named 999. etc) and I need to get them visable for the user in his mail client. I can see his other smtp files in his user area on the server but just... (12 Replies)
Discussion started by: tmware
12 Replies

7. Shell Programming and Scripting

mbox ascii mail text file ?

Hi, I am using "fetchmail" and "procmail" combination to trigger a job based on an input mail.Using fetchmail, incoming mail is downloaded from the mailserver to the local host.Once the mail is flushed,procmail starts execution and thereby triggers the application script. In-between... (3 Replies)
Discussion started by: DILEEP410
3 Replies

8. Shell Programming and Scripting

Send an attachment and html text both in the same mail

Hi all, I am working on UNIX (Solaris28). I would like to send an email in which the body will be in html format and, in the same mail, a xls file has to be attached. I have tried this: the file is correctly attached but the body comes as html source and not formatted. If I do not attach the... (4 Replies)
Discussion started by: stefan.yu
4 Replies

9. UNIX for Dummies Questions & Answers

Send text file to mail

I have a utility that opens a telnet session and allows me to execute commands through a script. The utility allows me to output to a text file whatever is outputted to screen. This utility runs from a DOS prompt in Windows 95/98, NT or 2000. How can I mail text file this to a certain user. I... (2 Replies)
Discussion started by: petrosi
2 Replies
Login or Register to Ask a Question