Mailing query results in tabular format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mailing query results in tabular format
# 1  
Old 05-09-2014
Mailing query results in tabular format

Hi ,

I am purging two tables based on date.

In my script I am taking the count of the tables purging them and then taking the after counts. I need to mail the before and after counts of the two tables in a mail in table format as mentioned in the result section.

For Eg:

## Count of the TAbles BEFORE PURGE
Code:
Bef_cnt_A=Select count(1) from A;
Bef_cnt_B=Select count(1) from B;


##PURGE
Code:
exp A
expdp B
truncate A
truncate B
imp A
imp b

##Count of Tables AFTER PURGE:
Code:
Aft_cnt_A=Select count(1) from A;
Aft_cnt_B=Select count(1) from B;

Result :

Code:
TABLES	              BEFORE COUNT	                          AFTER COUNT
Table A	    Count of table A before purging	     Count of table A after purging
Table B	    Count of table B before purging	     Count of table B after purging

Please help ... !!! Smilie
Moderator's Comments:
Mod Comment We need CODE tags on input, output, and code samples. Trying to guess at "tabular format" when CODE tags are not provided makes it harder to guess at what you want.

Last edited by CFA; 05-10-2014 at 06:58 PM.. Reason: Add more CODE tags.
# 2  
Old 05-11-2014
Could someone please help !!
Its Urgent :confused:

Last edited by CFA; 05-11-2014 at 10:58 AM..
# 3  
Old 05-11-2014
Guessing from the blue sky. Try
Code:
printf "%s\t%s\t%s\n" "TABLES" "BEFORE COUNT" "AFTER COUNT" "Table A" $Bef_cnt_A $Aft_cnt_A "Table B" $Bef_cnt_B $Aft_cnt_B | mail -s "table conts" user@domain.com

# 4  
Old 05-11-2014
Let's say the results are in results.txt in a tab delimited format
Code:
perl -alnF"\t" -e 'BEGIN {$/ = "\n"; $\ = "\n"; print "<TABLE>"};
  {print "<TR>"; foreach(@F) {print "<TD>$_</TD>"}; print "</TR>"};
  END {print "</TABLE>"}' results.txt > results.html

And you can email the results.html
# 5  
Old 05-13-2014
Thankyou so much RudiC and Srini !!

@Srini :

I am connecting to sql session and taking a spool of the BEFORE COUNT of the two tables (code below)
Code:
x=`sqlplus -s $ORACLE_LOGIN @temp.sql`

Please find the temp.sql below :

Code:
 
set echo off 
set heading off 
set feedback off 
set pagesize 0 
set verify off 
spool /home/menoarc/In.tsv 
select count(*) from A; 
select count(*) from B; 
spool off 
EXIT;

I close my sql session and perform the export import of the tables.
Code:
exp A
expdp B
truncate A
truncate B
imp A
imp b

I again connect to the sql session to spool the AFTER COUNTS of the two tables after the export import.
I use the same code for this

Code:
x=`sqlplus -s $ORACLE_LOGIN @temp.sql`

Please find the temp.sql below :

Code:
 
set echo off 
set heading off 
set feedback off 
set pagesize 0 
set verify off 
spool /home/menoarc/In.tsv 
select count(*) from A; 
select count(*) from B; 
spool off 
EXIT;

But as I am using the same temp.sql this overwrites the In.tsv file and I am only left with the after count in the In.tsv file.

Is there any way I can append the spool file with the after count of the tables ??

So that i can use a single file for the mail query you provided.

Please HELP !!!

Thanks in advance
CFA :S
# 6  
Old 05-13-2014
Try to rename the file /home/menoarc/In.tsv afther you run the "BEFORE COUNTS" and then run the "AFTER COUNTS"

Code:
BEFORE COUNTS SQL
mv /home/menoarc/In.tsv /home/menoarc/In_before.tsv
AFTER COUNTS SQL
cat /home/menoarc/In_before.tsv /home/menoarc/In.tsv > /home/menoarc/In.tmp && mv /home/menoarc/In.tmp /home/menoarc/In.tsv

# 7  
Old 05-16-2014
Thankyou so much Srini ...!!!

That worked Smilie Smilie

Now I have the before and after count in the tsv file as below:

Code:
1620 
4489
848
2456

where 1620 and 4489 is before count of table A and B
and 848 and 2456 is the after count of table A and B.

I am using the below code for mailing :

Code:
awk 'BEGIN { FS=" "; print "TABLES\tBEFORE_COUNT\tAFTER_COUNT"; } { print $1"\t"$2; }' In.txt > result.tsv
FROM='abc@xyz.com'
TO='abc@xyz.com'
SUBJECT="Weekly Purging for $date"
FILE="result.tsv"
(
echo "From: $FROM"
echo "To: $TO"
echo "Subject: $SUBJECT"
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<style>"
echo "table.metric { background-color: #FFFFFF; }"
echo "body { font-family: Arial, Helvetica, sans-serif; background-color: #FFFFFF; }"
echo "p { font-family: Arial, Helvetica, sans-serif; font-size: 12px; }"
echo "th { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: bold; }"
echo "th.metric { background-color: #003366; color: #FFFFFF; padding: 2px 4px; }"
echo "td { font-family: Arial, Helvetica, sans-serif; font-size: 12px; }"
echo "td.metric { background-color: #E5E8EF; }"
echo "</style>"
echo "<body>"
echo "<p> Please find the after and before purge counts for tables for $Date </p>"
echo "<table>"

# convert a TSV file to table format, first line is the header
head -1 $FILE | sed -e 's/      /<\/th><th class="metric">/g' -e 's/^/<tr><th class="metric">/' -e 's/$/<\/th><\/tr>/'
cat $FILE | sed -e 1d -e 's/    /<\/td><td class="metric">/g' -e 's/^/<tr><td class="metric">/' -e 's/$/<\/td><\/tr>/'

echo "</table>"
echo "</body>"
echo "</html>"
) | /usr/lib/sendmail $TO

the result i get is :

Code:
TABLES AFTER_COUNT  BEFORE_COUNT
1620 
4489
848
2456

I want it to be displayed in the below format:

Code:
TABLES   BEFORE_COUNT  AFTER_COUNT
A                 1620               848
B                 4489              2456


Please help !!! Smilie

---------- Post updated 05-16-14 at 02:37 AM ---------- Previous update was 05-15-14 at 02:42 PM ----------

Could someone please help !! Smilie Smilie
Its bit urgent ... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To have a mail in tabular format

Hello Guys, developing a monitoring shell script to have my queue depth count over mail . here is the sample input file to the script which has all the queue names 1 : DISPLAY QUEUE(*) WHERE (CURDEPTH GT 0) ZFC8409: Display Queue details. QUEUE(QL.GVR.ATA.CACHE.01) ... (10 Replies)
Discussion started by: wims
10 Replies

2. Shell Programming and Scripting

Required to get out put of log in tabular format in email body

Dears Please support I have out put in text file and look like below fixed inquiries - Click on MAX suffix http://server:port/app User Details http://server:port/app Audit User Detail Action hhttp://server:port/app fixed inquiries - Click on MAX suffix http://server:port/app User Details ... (13 Replies)
Discussion started by: mirwasim
13 Replies

3. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

4. Shell Programming and Scripting

Convert text file to HTML tabular format.

Please provide script/commands to convert text file to HTML tabular format. No need of styles and colours, just output and a heading in table is required. Output file will be send via email and will be seen from outlook. (script required without using awk). output file content: (sar... (7 Replies)
Discussion started by: Veera_V
7 Replies

5. Shell Programming and Scripting

Grep command output in tabular format

I have a grep command script which works fine and give the correct results but i wanted the output to be displayed in tabular format ? Is it possible to display the output in tabular format and as well direct them to some file. main script : #!/usr/bin/bash Start_Time=`date '+%m%d%y... (1 Reply)
Discussion started by: Optimus81
1 Replies

6. Shell Programming and Scripting

Convert data to a tabular format

How can i convert the below data to a simpler format :- cat tabular.txt User 1 Details :- First Name = Tom Middle Name = Last Name = Hanks Age = 40 Address = User 2 details :- First Name = Mike Middle Name = Last Name = Tyson Age = 50 Address = (2 Replies)
Discussion started by: lazydev
2 Replies

7. Shell Programming and Scripting

Extract data in tabular format from multiple files

Hi, I have directory with multiple files from which i need to extract portion of specif lines and insert it in a new file, the new file will contain a separate columns for each file data. Example: I need to extract Value_1 & Value_3 from all files and insert in output file as below: ... (2 Replies)
Discussion started by: belalr
2 Replies

8. UNIX for Advanced & Expert Users

How to export Result to Excel Tabular format from UNIX?

Hi I am working on a script in which I am firing a query on database through Unix and getting the result set. I want to export that in an excel file. I am able to do so nut the result are exported horizontally one below the other. Can anyone plss help me out in exporting the Result in Tabular... (4 Replies)
Discussion started by: Saritau3
4 Replies

9. Shell Programming and Scripting

Displaying output in the tabular format

Hi I want to display the following input data into the tabular format as shown in the output. Input.txt: Following jobs are in pending state for more than 10 minutes: JOB_ID JOB_SUBMIT_ID MAHAR 784308 PUNJA 109367 Following jobs are running for longer time: JOB_ID... (1 Reply)
Discussion started by: dats
1 Replies

10. Shell Programming and Scripting

Displaying the output in the tabular Format

Hi, I have a file which contains the data in the below format and need to develop a script which will give the output in the tabular format. Could you please advice me. Folder: Workflow: version . Workflow run status: Workflow run error code: Schedule time: Workflow run type: ... (2 Replies)
Discussion started by: kandi.reddy
2 Replies
Login or Register to Ask a Question