Solved

attach a zip file and send mail -- solaris

Posted on 2011-03-16
6
1,688 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
[X]
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
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

623 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