How would i mail in html format?(Formatting Help)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How would i mail in html format?(Formatting Help)
# 1  
Old 04-14-2011
How would i mail in html format?(Formatting Help)

I have written a scripts that checks the load average of server and if it is more than 5 it send a mail describing Current Load Average and High CPU/RAM processes .

The problem is I want to send these information in html form .I have done necessary coding to do the same but whenever i try to include the output of following It doesnt seems to be properly formatted.

Code:
echo "Top 10 CPU Utilized Processes" >> /tmp/Load_Average_Check.html
ssh -Tqn $1 ps auxf | sort -nr -k 3 | head -10 >> /tmp/Load_Average_Check.html
echo "-------------------------------------" >> /tmp/Load_Average_Check.html
echo "Top 10 Memory Utilized Processes" >> /tmp/Load_Average_Check.html
ssh -Tqn $1 ps auxf | sort -nr -k 4 | head -10 >> /tmp/Load_Average_Check.html

Output is as below.
Code:
******************************************************* Top 10 CPU Utilized Processes root 28679 2.5 0.0 34916 6688 ? Sl 00:05 20:59 \_ /usr/lib/xen/bin/qemu-dm -d 387 -domain-name XXXXXX -videoram 4 -k en-us -vnc 0.0.0.0:0,password -vncunused -vcpus 1 -boot c -localtime -serial pty -acpi -usbdevice tablet -net nic,vlan=1,macaddr=00:16:3E:67:92:4F,model=rtl8139 -net tap,vlan=1,ifname=tap387.0,bridge=XXXX -M xenfv root 32002 2.3 0.0 34712 4784 ? Sl Apr06 283:01 \_ /usr/lib/xen/bin/qemu-dm -d 372 -domain-name XXXXXXXX -videoram 4 -k en-us -vnc 0.0.0.0:0 -vncunused -vcpus 2 -boot c -localtime -serial pty -acpi -usbdevice tablet -net nic,vlan=1,macaddr=00:16:3E:19:32:09,model=rtl8139 -net tap,vlan=1,ifname=tap372.0,bridge=XXXX -M xenfv root 26933 1.9 0.0 0 0 ? Z 13:36 0:00 \_ [python] root 1815 1.9 0.0 35020 6852 ? Sl Feb17 1553:59 \_ /usr/lib/xen/bin/qemu-dm -d 261 -domain-name XXXXXX -videoram 4 -k en-us -vnc 0.0.0.0:0,password -vncunused -vcpus 2 -boot c -localtime -serial pty -acpi -usbdevice tablet -net nic,vlan=1,macaddr=XXXXXX,model=rtl8139 -net

Its so difficult to understand when i mail the information in plain text i can see the output properly formatted.

Is there any way i can send some part of script output in html while other in plain text ?
I hope i m not confusing ...
# 2  
Old 04-14-2011
HTML treats all white space as a single space, unless <PRE> or similar tags change the formatting. <PRE> looks like plain text but allows hyperlinks, but you have to escape literal &'"<> as &amp; (do amp first) &apos; &quot; &lt; &gt; . If you want to have the pretty fonts and data that aligns, you need a "<TABLE><TR><TD>a1<TD>a2<TR><td>b1...</Table>". You can postprocess UNIX command output to add the necessary tags and escapes using sed or such. Web stuff is a lot easier to script in PERL, as there are libs for all sorts of web stuff, almost PERLs reason for being, but I live without it, so if you want, you can, too.

For the mechanics of sending, there are several ways, and you can see the formats from your own html mail. Many clients send a plain text version along with html mail for primitive recipient client support.

Send an HTML file as email from the command line..
# 3  
Old 04-14-2011
Technically, email is raw text and nothing but raw text, by the way. Whether the client will understand it or just display a mess of tags is wholly up to the client program.
# 4  
Old 04-14-2011
Well, the raw text gets all mime'd up to send an email readable either in plain text or html, a multi-part, for which there are RFC's galore. To send raw email, I guess you might use sendmail barefoot or connect to port 25 of a mail forwarder and do your own esmtp (not that hard).

Here is a bit of the mail headers for an outlook mail message:
Code:
From: "Pickett, David" <david.pickett@bankofamerica.com>
Subject: nice to have a subject
To: "them@their.domain" <them@their.domain>
Message-ID: <0F0AC85C12F66949AB0572184DE7A1CB0606269944@ex2k.bankofamerica.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
          boundary="Boundary_(ID_oCNJgMBed65A0Phw5JVvIg)"
Content-Language: en-US
Accept-Language: en-US
Thread-topic: nice to have a subject
Thread-index: Acv6wA+3quoooFKoT5Cov80iv+jZDQ==
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
X-Proofpoint-Virus-Version: vendor=fsecure
engine=2.50.10432:5.2.15,1.0.148,0.0.0000
definitions=2011-04-14_07:2011-04-14,2011-04-14,1970-01-01 signatures=0

# 5  
Old 04-15-2011
Quote:
Originally Posted by DGPickett
Well, the raw text gets all mime'd up to send an email readable either in plain text or html, a multi-part, for which there are RFC's galore. To send raw email, I guess you might use sendmail barefoot or connect to port 25 of a mail forwarder and do your own esmtp (not that hard).

Here is a bit of the mail headers for an outlook mail message:
Code:
From: "Pickett, David" <david.pickett@bankofamerica.com>
Subject: nice to have a subject
To: "them@their.domain" <them@their.domain>
Message-ID: <0F0AC85C12F66949AB0572184DE7A1CB0606269944@ex2k.bankofamerica.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
          boundary="Boundary_(ID_oCNJgMBed65A0Phw5JVvIg)"
Content-Language: en-US
Accept-Language: en-US
Thread-topic: nice to have a subject
Thread-index: Acv6wA+3quoooFKoT5Cov80iv+jZDQ==
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
X-Proofpoint-Virus-Version: vendor=fsecure
engine=2.50.10432:5.2.15,1.0.148,0.0.0000
definitions=2011-04-14_07:2011-04-14,2011-04-14,1970-01-01 signatures=0

Thanks for the reply but i find it little difficult to understand.
Whenever i send the mail with plain text mail get properly formated.
But When the same is done with html tag some part of mail is not properly formatted (Some part= output of commands like ps aux)
# 6  
Old 04-15-2011
maybe a stupid question but what are you using to send the email? Whenever I send such html mails I use sendmail

have you tried mailx -m ? uuencode? sendmail?
# 7  
Old 04-15-2011
Quote:
Originally Posted by pkabali
maybe a stupid question but what are you using to send the email? Whenever I send such html mails I use sendmail

have you tried mailx -m ? uuencode? sendmail?
Have you ever tried to send output of ps -aux in html format?
Were you able to interpret the output?
I used sendmail as below.
Code:
sendmail  XYZ@ABC.com < /tmp/Load_Average_Check.html

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

HTML formatting in shellscript

I have written one script which connects to MYSQL database, fires one select query and send the results over an email, if there is any Output. But the Output which I am receiving over email is in text format. I need to get it dispalyed in tabular format to ensure better readability. Below is... (3 Replies)
Discussion started by: Sambit Sahu
3 Replies

2. Shell Programming and Scripting

[Solved] Sending a HTML email from cli loses formatting.

Hi, I have a .sh file, to email a report of our backups from a linux machine. It looks like this (minus a few bits): echo "HELO $host.$domain" sleep 1 echo "mail from: vdrreport@$domain" sleep 1 echo "rcpt to:$mailto" sleep 1 echo "data" sleep 1 echo "subject: $host VDR-Report... (2 Replies)
Discussion started by: cognito
2 Replies

3. UNIX for Dummies Questions & Answers

How would i mail in html format?(Formatting Help)

I have written a scripts that checks the load average of server and if it is more than 5 it send a mail describing Current Load Average and High CPU/RAM processes . The problem is I want to send these information in html form .I have done necessary coding to do the same but whenever i try to... (0 Replies)
Discussion started by: pinga123
0 Replies

4. Shell Programming and Scripting

html formatting using awk

Hi I have a file as given below: <table border=1> <TR><TH>Script Name</TH><TH>CVS Status</TH><TH>Script Location</TH></TR> <TR><TD><CENTER>Work Area: /home/ustst/</CENTER></TD></TR> <TR><TD><CENTER>admin_export.sh</CENTER></TD><TD><CENTER>Locally... (1 Reply)
Discussion started by: sudvishw
1 Replies

5. UNIX for Dummies Questions & Answers

How to send html file in a mail not as an attachment but it should display in the mail in table for

Hi The below script working when we are sending the html as attachment can u please guide how to send thesmae data in table form direct in the mail and not in mail attachment . cat Employee.sql SET VERIFY OFF SET PAGESIZE 200 SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON - HEAD... (0 Replies)
Discussion started by: mani_isha
0 Replies

6. Shell Programming and Scripting

Formatting isql output to horizontal format

Hi I am formatting informix isql output(vertical) to horizontal format. Suppose I have the following content in the flat file from isql output - item_nbr 0 usfn_label Subscriber Class usfn_name SBCLASS usfn_value bl5 item_nbr 1 usfn_label Switch Name usfn_name switchName... (2 Replies)
Discussion started by: nsinha
2 Replies

7. UNIX for Advanced & Expert Users

Mail x to HTML

Hi, i've build a script, 1: neon_script and the other 2:neon_mailing those to scripts i run with 3:neon_handmatig After that i get a mail in plain text in my mail box and i want it in html format. I already tried already a several things but nothings seems to work. Somebody got i idea how... (3 Replies)
Discussion started by: Rensen
3 Replies

8. UNIX for Advanced & Expert Users

unable to sent mail in html format by mailx command.

I use maix command to sent mails. i can sent only plain text mails. Unable to sent mails in html format. while sending mails in html format, the received mail has the html code only. (17 Replies)
Discussion started by: p_prathaban
17 Replies

9. Shell Programming and Scripting

formatting output in html

hello all. I was hoping someone may have an idea or two. I'm throwing together a shell script that does a lot of application and system level data collection. The idea is is you run it before/after restarting an application for later analysis. A lot of stuff is collected... resource stats,... (4 Replies)
Discussion started by: ebbtide
4 Replies

10. Windows & DOS: Issues & Discussions

formatting a Compact Flash in DOS format

:confused: I tryied to use the mount Command (and the msdos.utils) in Darwin 1.4 (OS X) to format a Compact Flash in DOS Format (I had already this native format but I changed it with Disk Utility in MacOS standard and the PC Card slot of a Windows 98-Laptop can't nore read the card) I want to... (1 Reply)
Discussion started by: dreamsurfer
1 Replies
Login or Register to Ask a Question