Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

attach a zip file and send mail -- solaris

Posted on 2011-03-16
6
1,582 Views
Last Modified: 2012-05-11
Hi all -

            I need to write a shell where in I need to create a zip file and use that zip file as an attachment and send mail. right now , I was able to do is sending file. I am able to create zip, but some how the whole process is not working. Can you please help?

Regards



DATE=`date '+DATE: %m/%d/%y%nTIME:%H:%M:%S'`
RETURN_ADDRESS="test@mymail.com"
SUBJECT="report as of`date '+DATE: %m/%d/%y%nTIME:%H:%M:%S'`"
EMAIL_ADDRESS="mymail@test.com"
ATTACHED_FILE="/opt/jobs/report.html"
USERSREPORT= zip -r UsersReport.zip $ATTACHED_FILE
# mail variables end ############
cat "$USERSREPORT" | mailx -r "$RETURN_ADDRESS" -s "$SUBJECT"   "$EMAIL_ADDRESS"

Open in new window

0
Comment
Question by:akp007
  • 3
  • 2
6 Comments
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
ID: 35151275
instead of

cat "$USERSREPORT" | mailx -r "$RETURN_ADDRESS" -s "$SUBJECT"   "$EMAIL_ADDRESS"

use

uuencode "$USERSREPORT" | mailx -r "$RETURN_ADDRESS" -s "$SUBJECT"   "$EMAIL_ADDRESS"

 but, what

USERSREPORT= zip -r UsersReport.zip $ATTACHED_FILE

is supposed to do?
0
 
LVL 3

Expert Comment

by:Alberto Cortes
ID: 35151398
Solution:

Remove line 6, where you assing the variable USERSREPORT. You do not need this.
Replace line 8 using next two lines:
  zip -r UsersReport.zip $ATTACHED_FILE
  mailx -r "$RETURN_ADDRESS" -s "$SUBJECT"   "$EMAIL_ADDRESS" < UsersReport.zip
0
 

Author Comment

by:akp007
ID: 35151552
I tried mailx -r "$RETURN_ADDRESS" -s "$SUBJECT"   "$EMAIL_ADDRESS" < UsersReport.zip

what happened was , the I am getting the mail , but the attachment is coming in the message body

Regards
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 40

Expert Comment

by:omarfarid
ID: 35151598
did you try the uuencode rather cat ?
0
 

Author Comment

by:akp007
ID: 35156795
thanks omarfraid. I tried the uuencode. to be honest, I have tried that before I posted the question, the same way as you mentioned. but it did not work. I had to alter the command the following way to get it work.

uuencode UsersReport.zip UsersReport.zip |  mailx -r "$RETURN_ADDRESS" -s "$SUBJECT"   "$EMAIL_ADDRESS"

the only problem I have now is the zip file is still holding the directory structure

Regards



0
 
LVL 40

Expert Comment

by:omarfarid
ID: 35159399
what do you mean by "the only problem I have now is the zip file is still holding the directory structure"?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AIX    Volume group Auto ON/OFF question 2 116
check unix curl command return value 7 151
Sed question 2 100
Authenticate using sesu from script 7 54
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question