Solved

attach a zip file and send mail -- solaris

Posted on 2011-03-16
6
1,567 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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 …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

770 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