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. |
Hello s_linux :)
How exactly are you sending the mail in your script? It looks like you missed off the double quotes. Best Charles |
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. |
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 |
Quote:
|
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 |
it could be your email client. are you by any chance using a windows-based email client?
|
I'm using MS outlook. does it matters? If so How can I get nicer message. Thanks
|
Hello s_linux :)
Quote:
Have replicated your method and it worked as you want: Code:
c@CW8:~$ cat Result 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 CHarles |
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 |
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 |
you could also try:
Code:
|
Quote:
I've never used uuencode. Will that be readable by most email readers? |
@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 ... ? |
Quote:
|
All times are GMT -5. The time now is 11:46 AM. |