LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE
User Name
Password
SUSE / openSUSE This Forum is for the discussion of Suse Linux.

Notices


Reply
  Search this Thread
Old 07-23-2009, 02:13 PM   #1
s_linux
Member
 
Registered: Jul 2009
Posts: 83

Rep: Reputation: 15
send an email of script output


Hi All,

I'm trying to send some file which generated by script to my email. when I run the script I'm getting an email. Thats fine. But it seems to be all messed up like below

Memory Status on ServerA: Mem: 3867444k total, 862680k used, 3004764k free, 54456k buffers!! CPU Status on ServerA: Cpu(s): 1.8%us, 2.3%sy, 0.1%ni, 94.1%id, 0.6%wa, 0.0%hi, 1.1%si, 0.0%st DEV POrt are OK on ServerA. Service is running. Memory Status on ServerB: Mem: 3867444k total, 862680k used, 3004764k free, 54456k buffers!! CPU Status on ServerA: Cpu(s): 1.8%us, 2.3%sy, 0.1%ni, 94.1%id, 0.6%wa, 0.0%hi, 1.1%si, 0.0%st DEV POrt are OK on ServerB. Service is running.on ServerB


I want to make it seperate lines like below

Memory Status on ServerA: Mem: 3867444k total, 862680k used, 3004764k free, 54456k buffers!!
CPU Status on ServerA: Cpu(s): 1.8%us, 2.3%sy, 0.1%ni, 94.1%id, 0.6%wa, 0.0%hi, 1.1%si, 0.0%st
DEV POrt are OK on ServerA.
Service is running on ServerA.


Memory Status on ServerB: Mem: 3867444k total, 862680k used, 3004764k free, 54456k buffers!!
CPU Status on ServerB: Cpu(s): 1.8%us, 2.3%sy, 0.1%ni, 94.1%id, 0.6%wa, 0.0%hi, 1.1%si, 0.0%st
DEV POrt are OK on ServerB.
Service is running on ServerB.

Is there anyway to do so in the script. Thanks.
 
Old 07-23-2009, 02:30 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Hello s_linux

How exactly are you sending the mail in your script? It looks like you missed off the double quotes.

Best

Charles
 
Old 07-23-2009, 02:53 PM   #3
s_linux
Member
 
Registered: Jul 2009
Posts: 83

Original Poster
Rep: Reputation: 15
Thanks for your reply. I'm sending mail with following command in my script ..

mail -s "Health Check Status" uname@company.com < /home/uname/Result

Thanks again.
 
Old 07-24-2009, 01:20 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You can try either a here document or process substitution, using cat to print out the file content:
Code:
$ mail -s "Health Check Status" uname@company.com << EOF
> $(cat /home/uname/Result)
> EOF
$
$ mail -s "Health Check Status" uname@company.com < <(cat /home/uname/Result)
$
 
Old 07-24-2009, 02:46 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by s_linux View Post
Thanks for your reply. I'm sending mail with following command in my script ..

mail -s "Health Check Status" uname@company.com < /home/uname/Result

Thanks again.
That ought to work. What do the contents of /home/uname/Result look like? If they don't look OK then how are you creating the file?
 
Old 07-24-2009, 08:18 AM   #6
s_linux
Member
 
Registered: Jul 2009
Posts: 83

Original Poster
Rep: Reputation: 15
Thanks for your replies..

$ mail -s "Health Check Status" uname@company.com << EOF
> $(cat /home/uname/Result)
> EOF
$
$ mail -s "Health Check Status" uname@company.com < <(cat /home/uname/Result)
$

I tried this but still the same thing. email message looks very messy.

That ought to work. What do the contents of /home/uname/Result look like? If they don't look OK then how are you creating the file?

my intial post was actuvally /home/uname/Result file. Im generating this file as script output.

in the file it looks good. But in email message only messy.

Can we just attach the file instead. Thanks
 
Old 07-24-2009, 08:33 AM   #7
rn_
Member
 
Registered: Jun 2009
Location: Orlando, FL, USA
Distribution: Suse, Redhat
Posts: 127
Blog Entries: 1

Rep: Reputation: 25
it could be your email client. are you by any chance using a windows-based email client?
 
Old 07-24-2009, 09:03 AM   #8
s_linux
Member
 
Registered: Jul 2009
Posts: 83

Original Poster
Rep: Reputation: 15
I'm using MS outlook. does it matters? If so How can I get nicer message. Thanks
 
Old 07-24-2009, 09:10 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Hello s_linux
Quote:
Originally Posted by s_linux View Post
[snip]
in the file it looks good. But in email message only messy.

Can we just attach the file instead. Thanks
AFAIK the mail command does not support attachments.

Have replicated your method and it worked as you want:
Code:
c@CW8:~$ cat Result
Memory Status on ServerA: Mem: 3867444k total, 862680k used, 3004764k free, 54456k buffers!!
CPU Status on ServerA: Cpu(s): 1.8%us, 2.3%sy, 0.1%ni, 94.1%id, 0.6%wa, 0.0%hi, 1.1%si, 0.0%st
DEV POrt are OK on ServerA.
Service is running on ServerA.


Memory Status on ServerB: Mem: 3867444k total, 862680k used, 3004764k free, 54456k buffers!!
CPU Status on ServerB: Cpu(s): 1.8%us, 2.3%sy, 0.1%ni, 94.1%id, 0.6%wa, 0.0%hi, 1.1%si, 0.0%st
DEV POrt are OK on ServerB.
Service is running on ServerB.
c@CW8:~$ mail -s "Health Check Status" root < Result
c@CW8:~$ dpkg -l mailx | grep mailx
ii  mailx                                      1:8.1.2-0.20071017cvs-2                              A simple mail user agent
Mail was received (in MS Outlook) looking just fine.

Time to dig into the details. Mail/mailx/mail has been around for a long time and is (?) no longer being developed. It is unlikely that the different behaviour on your system and mine is caused by features of different versions.

Stupid question first. How are you viewing the mail when you see it with line ends and empty lines replaced with spaces?

Do you have a ~/.mailrc file. If so, rename it to something else and try again, to see if it's something in there that's causing the problem.

What does your /etc/mail.rc file look like. Here's mine, not touched since installation
Code:
c@CW8:~$ cat /etc/mail.rc 
set ask askcc append dot save crt
ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via Delivered-To
Best

CHarles
 
Old 07-24-2009, 09:46 AM   #10
s_linux
Member
 
Registered: Jul 2009
Posts: 83

Original Poster
Rep: Reputation: 15
If I do cat Result, I got similar result as you got but in email message it looks messy.

I dont see any ~/.mailrc file in my server.

Here is the output of mail.rc file

$ cat /etc/mail.rc
set asksub append dot save crt=20
ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via

I just changed to mail.rc file as you have but no luck. Thanks
 
Old 07-24-2009, 09:52 AM   #11
rn_
Member
 
Registered: Jun 2009
Location: Orlando, FL, USA
Distribution: Suse, Redhat
Posts: 127
Blog Entries: 1

Rep: Reputation: 25
The line termination characters are different in unix and windows, and that sometimes causes a problem. I think a lot of newer win apps are able to handle the nix EOL, but there are still some out there (eg. notepad) that won't handle it. if you're using an older version of outlook it might still have the problem.

if attaching the doc works for you, you could always uuencode it and pass it to the mail prog, like so:

Code:
uuencode /home/uname/Result Result.txt | mail -s "Health Check Status" uname@company.com
for some reason my distro doesn't have uuencode, but i found a gmime pkg that does the same; instead of uuencode use gmime-uuencode.
 
Old 07-24-2009, 09:56 AM   #12
rn_
Member
 
Registered: Jun 2009
Location: Orlando, FL, USA
Distribution: Suse, Redhat
Posts: 127
Blog Entries: 1

Rep: Reputation: 25
you could also try:

Code:
cat /home/uname/Result | unix2dos | mail -s "Health Check Status" uname@company.com

Last edited by rn_; 07-24-2009 at 09:57 AM.
 
Old 07-24-2009, 10:01 AM   #13
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by rn_ View Post
The line termination characters are different in unix and windows, and that sometimes causes a problem. I think a lot of newer win apps are able to handle the nix EOL, but there are still some out there (eg. notepad) that won't handle it. if you're using an older version of outlook it might still have the problem.

if attaching the doc works for you, you could always uuencode it and pass it to the mail prog, like so:

Code:
uuencode /home/uname/Result Result.txt | mail -s "Health Check Status" uname@company.com
for some reason my distro doesn't have uuencode, but i found a gmime pkg that does the same; instead of uuencode use gmime-uuencode.
Interesting suggestions. FWIW, I routinely send reports generated by smartmontools on ubuntu to myself using "mail" and they look OK in Outlook 2003.

I've never used uuencode. Will that be readable by most email readers?
 
Old 07-24-2009, 10:07 AM   #14
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
@s_linux

Can you send a copy to yourself on the Linux system and see what it looks like there? It would help to know when the mangling happens -- on the Linux system or later. The mail -c option followed by your username (without any @domain_name) should do it.

What are you using to send the mail from your Linux system to wherever? postfix, sendmail ... ?
 
Old 07-24-2009, 10:09 AM   #15
rn_
Member
 
Registered: Jun 2009
Location: Orlando, FL, USA
Distribution: Suse, Redhat
Posts: 127
Blog Entries: 1

Rep: Reputation: 25
Quote:
Originally Posted by catkin View Post
Will that be readable by most email readers?
yes AFAIK. uuencode is a pretty standard way to attach docs. it works with my outlook client.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to send email... bfloeagle Linux - General 5 10-13-2009 10:20 AM
send output of mysql query to email within same script hattori.hanzo Linux - Newbie 2 12-03-2008 03:14 AM
send email from a script r.stiltskin Ubuntu 7 07-26-2008 12:36 AM
how to send the output of cronjobs to another email address ? kirtikjr Linux - Software 1 07-12-2007 05:36 PM
How to send an email within a script??? johnsanty Programming 19 09-02-2006 12:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE

All times are GMT -5. The time now is 07:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration