issues in sending mail


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers issues in sending mail
# 1  
Old 08-09-2011
issues in sending mail

Hi,

i am trying the below script for sending mail.

Code:
if [ -s $sfile ]
then
count=`cat $sfile|wc -l`
echo "There are $count abends.Please take care " > body.txt
(cat body.txt;uuencode $sfile $sfile) |  mailx -s "Alert:there are failures" pandeesh@gmail.com
fi

In the mail, i am getting like:
Code:
There are       20 abends.Please take care 

There's a lot of space between 20 and are. i want it with proper spaces alignment.
Is there any way to specify the 20 in some other font or color?

And also the contents of the attachment is not in proper way.

While viewing the $sfile in unix, the contents are displaying line by line:
Code:
abc
cde
efg
hgi

But while viewing the mail attachment the contents are coming like:

Code:
abccdeefghgi

Please help me to resolve these issues?

Thanks
# 2  
Old 08-09-2011
For problem 1:
Code:
count=`wc -l < $sfile`

That brings just 20 without the space in front of it and removes a useless cat.

For problem 2:
Code:
tr -s '\n' ' ' < $sfile

This will change all newlines versus a blank. Maybe you can use this inside your script when assigning it to a variable or whatever.
This User Gave Thanks to zaxxon For This Post:
# 3  
Old 08-09-2011
Quote:
Originally Posted by zaxxon
For problem 1:
Code:
count=`wc -l < $sfile`

That brings just 20 without the space in front of it and removes a useless cat.

For problem 2:
Code:
tr -s '\n' ' ' < $sfile

This will change all newlines versus a blank. Maybe you can use this inside your script when assigning it to a variable or whatever.
The solution fo rproblem1 is fine. i need more clarity in solution for problem 2.
while viewing in unix cat $sfile, it's displaying the contents properly.
But while attaching the $sfile using uuencode, the problem occurs.

After recieving the mail if i open the attachment , all the 20 lines got combined in a single line.

I want it in 20 lines even in attachment too.
How to achieve this?

Thanks
# 4  
Old 08-09-2011
Ah you send it as an attachment ok. I guess that's a problem of the mail client you are viewing the attachment with. It might expect <CR><LF> and since this file is coming from a Unix/Linux box (my assumption) it will only contain <CR>.

You could try to use this on the attachment before you send it:
Code:
sed 's/$'"/`echo \\\r`/" attachment.old > attachment.new

# 5  
Old 08-09-2011
Quote:
Originally Posted by zaxxon
For problem 1:
Code:
count=`wc -l < $sfile`

That brings just 20 without the space in front of it and removes a useless cat.

For problem 2:
Code:
tr -s '\n' ' ' < $sfile

This will change all newlines versus a blank. Maybe you can use this inside your script when assigning it to a variable or whatever.
Hi the soultion fo rproblem 1 is not working exactly . For the code:
Code:
count=`wc -l < $sfile`
 echo "There are $count abends .Please take care " > body.txt
 sed 's/$'"/`echo \\\r`/" $sfile > $sfile.txt
(cat body.txt;uuencode $sfile.txt $sfile.txt) |  mailx -s "Alert:there are some Abends" pandeesh@gmail.com
rm $sfile
fi

Now the attachment comes properly.
But the body text still comes as:
Code:
There are       20 abends .Please take care

Any idea to avoid that spaces between are and 20. i need only one space.

Thanks

---------- Post updated at 01:37 PM ---------- Previous update was at 01:30 PM ----------
Code:
count=`cat $sfile|wc -l|sed -e 's/^[ \t]*//'`[

resolves the space issue. thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issues sending emails using PostFix Mail Server

I'm unable to send email from my Linux server despite SMTP port 25 Active and Listening. # hostname TechX I checked the mail log ( /var/log/maillog ) and found the below error. I'm sharing all the ".cf" files seen in the error log. 1. # more /etc/postfix/main.cf # postfix... (0 Replies)
Discussion started by: mohtashims
0 Replies

2. Red Hat

Problems sending mail: Difference between Mail and Mailx?

Whats the difference between mail and mailx? I'm trying to troubleshoot a problem where I can send mail from server A with this `echo $MESSAGE | mail -s "$SUBJECT" -r $FROM $RECIPIENTS` command but executing the same command from server B throws me this error (Both servers are RHEL) ... (1 Reply)
Discussion started by: RedSpyder
1 Replies

3. UNIX for Dummies Questions & Answers

Issues in sending mail with attachements

Hi I am using the below command to send mail from unix with body as well as attachment. But the attachment is in encoded form in the body itself. I am not receiving as attachment: (cat body_success.txt;uuencode Log.txt Log.txt)| mailx -s "success" $ToID I am receiving... (5 Replies)
Discussion started by: pandeesh
5 Replies

4. Shell Programming and Scripting

Stop sending mail after certain number of mail

Hi guys... I am busy writing a script to notify me via an mail if my application is down. I have done that. Now I want this script to stop sending mails after five mails were sent but the script should keep on checking the application. When the application is up again that count should be... (5 Replies)
Discussion started by: Phuti
5 Replies

5. UNIX for Advanced & Expert Users

Issues while sending a mail having records fetched from SQL -all in UNIX

hi-I want to write a UNIX Script which will fetch records from Oracle database.I want to store these records in a file under fields like email address,name and the transaction_id and then fetch these records from the file and send the email to individual users with their transaction ID details. (4 Replies)
Discussion started by: DeepSalwan
4 Replies

6. UNIX for Dummies Questions & Answers

sending a mail to a mail client

Hi everyone! I'm trying to create a database monitoring script that reads an alert file and sends an error message if it can 'grep' a particular string. Is there a way to send this message to a mail client using SMTP? Even better, is there any place on this site that has these kinds of... (5 Replies)
Discussion started by: solaris73
5 Replies
Login or Register to Ask a Question