LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-11-2008, 04:17 AM   #1
Swapna173
LQ Newbie
 
Registered: Dec 2007
Posts: 25

Rep: Reputation: 15
Mail Structure Format


Hi Guys,

I have a file which has some mail body. and another file that is spooled from sqlplus which is delimited by "|". Now, when i redirect the contents of spooled file to mailbody.txt file. it is perfect but when the mail is composed with the mailbody.txt. The mailbody after mail is sent has changed the formattting of the tabular data format and supressed all the spaces.

How can I preserve the spaces in the mail.

Another thing is how can i check and capture the sql errors like database connectivity and space of the database has exceeded. Becoz i am redirecting the output of all the process to a log file.

Swapna
 
Old 08-11-2008, 04:33 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Using sqlplus in a scripting environment is pretty ugly. I remember having terrible trouble getting it to tell me if there was an error in a sensible way (i.e. setting $? as I would like). There are some SET commands which can help out, but I don't think I ever found a very satisfactory solution.

In the end I think I tried two approaches:
  1. re-directing all output to a temporary file, greping for error messages of various kinds, and doing some post-processing to neaten up the output
  2. giving up and using Perl/DBI.

Not sure about the tab issue, but it's safe to say the perl/DBI approach will solve that too.

Sorry if that's a bit vague - it's been a while since I used it.

Last edited by matthewg42; 08-11-2008 at 04:37 AM.
 
Old 08-11-2008, 05:14 AM   #3
Swapna173
LQ Newbie
 
Registered: Dec 2007
Posts: 25

Original Poster
Rep: Reputation: 15
Hi Matthew,

Sqlplus spool has given the desired output. But while sending the mail the mail command has changed the mail body format where mailbody was stored in a file.

The command used was :

cat mailbody.txt | mail -s "$mailsubject" $adminmailid

where mailbody.txt contains formatted mailbody which is as follows:


ETL Process Successfully Completed.


Measure Name ,File Name ,File Record Count ,Data Loaded
-------------------- ,-------------------- ,-------------------- ,--------------------
Cost - Actual ,data_vistaar_plant_mfg_actual ,121929 ,96
Field Units on Hand US ,field_units_on_hand_us_actual ,4775263 ,148881
Instrument Cost - Actual ,data_vistaar_plant_mfg_actual ,121929 ,96
List Price ,list_price_actual ,File Not Found ,
Plant Of Manufacture ,data_vistaar_plant_mfg_actual ,121929 ,96
Sales Amount - Actual ,sales_source_actual_ous ,47346 ,251321
Sales Amount - Actual ,sales_source_actual_us ,881847 ,251321
Sales Units - Actual ,sales_source_actual_ous ,47346 ,251321
Sales Units - Actual ,sales_source_actual_us ,881847 ,251321
Total Reserve - Actual ,data_reserve_at_mtg_cost_actual ,16009 ,5375
US Mfg Units on Hand ,us_mfg_units_on_hand_actual ,579525 ,122413

Last edited by Swapna173; 08-11-2008 at 05:21 AM.
 
Old 08-11-2008, 05:22 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Oh I think I see.

Maybe you could send the file as a MIME attachment, rather than in the message body? I'm a Perl fan, so I'd probably use one of the Perl MIME modules to generate the message, but I'm sure there are command line tools for that sort of thing.
 
Old 08-11-2008, 08:30 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,254

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
If you really want to stick to shell, install the 'nail' mail client, which can handle attachments. That'll preserve the formatting.
http://linux.die.net/man/1/nail
 
Old 08-11-2008, 09:26 PM   #6
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Hmmm, something's not expected here. The mail command should not be collapsing multiple spaces into a single space.
 
Old 08-12-2008, 10:06 AM   #7
Swapna173
LQ Newbie
 
Registered: Dec 2007
Posts: 25

Original Poster
Rep: Reputation: 15
HI Guys,

I got know something like on the mail format. when i tranferred the file that i am inserting in the mail body to the windows machine and opened in the Excel.

The entire line was displayed in the single cell.
and i created the file through spool in sqlplus with colsep as "," and tried with "|", tab and some limitations of space.

can i get to know how to create a tsv file in linux through spool and use the same in the mailbody which will preserve the format.

Or else how can i convert a lst file to csv in linux/unix.

Swapna

Last edited by Swapna173; 08-12-2008 at 10:41 AM.
 
Old 08-12-2008, 12:27 PM   #8
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Excel uses tab as the default separator character. It is not clear how you are transferring the file or contents to windows and hence to into Excel (copy/paste, directly opening a saved mail body?).

If you paste text into Excel that doesn't not have tabs, and does not have the proper line terminators, it will paste into a single cell.

I'll repeat my comment from post #6. The mail protocol is not changing the text formatting of your text body. It doesn't convert tabs into spaces, and it doesn't compress spaces into a single space. It must encode upon sending, and decode upon receipt. Any conversion is happening by your mail clients or other mail processing software.

This really is not a mail structure question any longer.
 
Old 08-12-2008, 08:16 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,254

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Create the output as csv in SQLPLUS (colsep=',') and import into Excel, specifying the filetype as csv.
Its in the menus somewhere
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Home Jail Folder Structure like Gobolinux Directory Structure luispt Linux - General 3 07-26-2008 07:46 PM
TB open TB Format mail in folder saved in SCSI External HD tuxbunta LinuxQuestions.org Member Intro 2 04-15-2006 07:05 AM
Import Mail from /var/spool/mail (sendmail) to a MailDir Format in Postfix shawnbishop Linux - Software 0 04-06-2006 11:44 AM
costly book in ur mail box in pdf format abimanyu007 Linux - General 2 11-04-2004 11:49 AM
E-mail Evolution veiwing HTML Format David@330 Linux - Newbie 5 09-15-2004 10:44 AM


All times are GMT -5. The time now is 08:41 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration