Solved

attach a zip file and send mail -- solaris

Posted on 2011-03-16
6
1,509 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
IBM flash storage 840 15 51
how to check for shares on aix 1 53
Linux: disable vim auto-comment 7 64
Write an app 10 61
Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now