Solved

attach a zip file and send mail -- solaris

Posted on 2011-03-16
6
1,533 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
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…

911 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

16 Experts available now in Live!

Get 1:1 Help Now