The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
mailx commannd - Mail and Attachment in same mail sharif UNIX for Advanced & Expert Users 6 03-19-2008 01:25 PM
Send email with attachment in form of excel in unix bdebroy Shell Programming and Scripting 8 09-05-2007 02:39 AM
How To Add Attachment to Mail lesstjm Shell Programming and Scripting 3 12-06-2005 08:24 AM
mail attachment sushrut UNIX for Dummies Questions & Answers 3 08-27-2001 11:14 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-24-2008
Registered User
 

Join Date: Jul 2008
Posts: 4
Excel attachment in e-mail

Hi,

I have to send the query output as an excel attachmet from UNIX Shell script, for this i have written following shell script and sql file this shell script has created the ho.xls file with correct query output but it doesn't generate the mail that shold contain query output as an excel attachment, could anyone please tell me the correct script for my requirement.

Will the script generate the log file as an excel file?

I am using Sun OS 5.6 and Oracle 8i

ho.sh
------

#!/bin/csh
setenv ORACLE_HOME /opt/app/oracle/product/8.1.7
setenv ORACLE_SID environ
set BINARIES=/usr/bin
set APPDIR=/u08/Temp
$ORACLE_HOME/bin/sqlplus uname/pwd @$APPDIR/ho.sql > $APPDIR/ho.xls
uuencode $APPDIR/ho.xls $APPDIR/ho.xls | /usr/bin/mailx -s "Attachment" karthikeyanjo@hcl.in

ho.sql
------
set lines 200
set pagesize 100
select to_char(transaction_date,'HH24')||':00 - '||to_char(transaction_date,'HH24')||':59' "Hour",
count(*) "Total_Hits"
from adsl_interface_log_cng
where trunc(transaction_date)=trunc(sysdate-1)
AND (decode(TRANSLATE(UPPER (adsl_ra_reasoncode),'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!"##$%^&*()-_=+[{]}@;:#~,<.>/?`?/'' ','1234567890'),0,NULL,
TRANSLATE(UPPER (adsl_ra_reasoncode),'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!"##$%^&*()-_=+[{]}@;:#~,<.>/?`?/'' ','1234567890'))
/10) < 2
group by to_char(transaction_date,'HH24')
order by to_char(transaction_date,'HH24');
Reply With Quote
Forum Sponsor
  #2  
Old 07-24-2008
joeyg's Avatar
Moderator
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 983
Question Does it give an error?

I do not see anything wrong in syntax with your command.

a) can you manually ftp the .xls file to your pc and verify it as good?
b) instead of uuencode the .xls, can you try and send the ho.sh file?

The answer to these two questions should start the error-correction process.
Reply With Quote
  #3  
Old 07-24-2008
Registered User
 

Join Date: Jul 2008
Posts: 4
Excel attachment in e-mail

Hi,

Is it possible to generate an excel file by UNIX Shell script?

I have modify the ho.sh script as follows and i have made spool file in sql file as spool /u08/Temp/ho.txt

ho.sh
------

#!/bin/csh
#!/bin/bash
#!/bin/ksh
setenv ORACLE_HOME /opt/app/oracle/product/8.1.7
setenv ORACLE_SID riker
set BINARIES=/usr/bin
set APPDIR=/u08/Temp
$ORACLE_HOME/bin/sqlplus adsl_stats/adsl_stats01 @$APPDIR/ho.sql
uuencode $APPDIR/ho.txt $APPDIR/ho.txt | mailx -s "Attachment" mail@com

The above script generate the mail with text file that conatins the query output as an attachment in crontab but while ftping the file it shows permission denied( i hve given chmod 777 to this file).

Could you please tell me any command or script that should convert the text file into an excel file in UNIX, i nedd to schedule it in crontab with mail generation option.

Thanks in advance
Reply With Quote
  #4  
Old 07-25-2008
joeyg's Avatar
Moderator
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 983
Wink Excel file from unix

Two methods for this:
(a) There are specific add-ons you can obtain that allow fairly extensive use of Excel commands and functions to be created by a unix shell.
or...
(b) Create a .csv file. Excel can open (and write) .csv files. So, you could build a file along the following idea. Please note is is not complete code, but a sample of some of the commands to use. [I do many of these in my job - creating reports others can read in Excel.]

Code:
csv_f="my_excel.csv"
echo "John Doe","12 Main Street Boston MA",100,10 >>$csv_f
echo "Karthi Key","52 Commercial Way New York NY",200,5 >>$csv_f
uuencode "$csv_f" "$csv_f" | mailx -s "important excel" karth@anywhere.com
Reply With Quote
  #5  
Old 07-25-2008
Registered User
 

Join Date: Jul 2008
Posts: 4
Excel attachment in e-mail

Hi,

Thank you for your reply

Finally i got the correct output with following scripts

ho.sh
------

#!/bin/csh
#!/bin/bash
#!/bin/ksh
setenv ORACLE_HOME /opt/app/oracle/product/8.1.7
setenv ORACLE_SID riker
set BINARIES=/usr/bin
set APPDIR=/u08/Temp
$ORACLE_HOME/bin/sqlplus adsl_stats/adsl_stats01 @$APPDIR/ho.sql > ho.xls
uuencode ho.xls ho.xls | mailx -s "Attachment" karthikeyanjo@hcl.in

ho.sql
------
set feedback off
set echo off
set pagesize 100
select to_char(transaction_date,'HH24')||':00 - '||to_char(transaction_date,'HH24')||':59' "Hour",
count(*) "Total_Hits"
from adsl_interface_log_cng
where trunc(transaction_date)=trunc(sysdate-1)
AND (decode(TRANSLATE(UPPER (adsl_ra_reasoncode),'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!"##$%^&*()-_=+[{]}@;:#~,<.>/?`?/'' ','1234567890'),0,NULL,
TRANSLATE(UPPER (adsl_ra_reasoncode),'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!"##$%^&*()-_=+[{]}@;:#~,<.>/?`?/'' ','1234567890'))
/10) < 2
group by to_char(transaction_date,'HH24')
order by to_char(transaction_date,'HH24');

If i create the spool file in sql script as ho.xls also gave the output but the output is combined in single column and the spool file size is more compare to above one.
Reply With Quote
  #6  
Old 08-12-2008
Registered User
 

Join Date: Jul 2008
Posts: 4
uuencode

Hi,

Can u send me the script/command you have used.

Regards,
Karthik
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0