Email with attachment from local machine through UNIX

Hello everyone,
So, here is my requirement.
I want to run an SQL query and export the result in an excel file and send that as an attachement in an email to the intended receipients.

Please help me understand how to do that.
How to connect to database, how to export the output in an excel file and how to attach it to an email and send it.

Also let me know if a file from local machine can be attached and sent through email by a unix/linux command.

P.S: I am a beginner in UNIX/Linux.

Thanks in advance :slight_smile:

find yourself a copy of metamail. Some distros of Linux don't supply metamail anymore, but at the same time, they don't seem to be supplying an alternative either.

You're asking 3 questions.

SQL query
Send as attachment
Import into Excel

This depends on the SQL client you're using; however, mostly every SQL UNIX client can do something like this, here is an example using mySql.
I have a file that contains my sql statements: my.sql.query.file and I save the results in file saved.query.txt (this is not the only way to run sql commands from the command )...

mysql -b -u username -p password <my.sql.query.file > saved.query.txt

Note: the use of the -b switch will use tab as the delimiter between fields in the saved.query.txt file. You will have to consult your sql client to see if you can specify an output field delimeter. I think the default for mysql is comma with field enclosed in "

Sending attachments in email can be done in this fashion (this is
the traditional way of sending attachments...

uuencode saved.query.txt saved.query.txt | mail user@somehost.org

Since I used the -b option on my output file, I simply import it into excel asking it to use tab as the delimeter.

What you are asking is to basically design and code an application.

I'm providing you what you asked directly, we are not a coding service.
You are asking:
how to email a file as an attachment
Oracle with a tab delimited csv file:

sqlplus -s user/passwd@instance <<EOF
set colsep '   '   -- there is a tab character between the  ' '
spool file.csv
@some_sql_report_someone_wrote.sql
spool off
EOF

email:

uuencode file.csv file.csv | mailx -s 'Excel format report' somebody@yourcompany.com

Next time please make an effort and show what you did. Give information about your UNIX system and the database: sql server, oracle, db2. This directly answered your questions, but it is next to useless for you, in the same way your question is not useful for us.