hi.. how to attach a tar file using shell script

Hi,

How to attach a tar file using shell script or the command liine..

I following command just send the mail to the person with .txt file as body, I want to send it as attachment.

/usr/sbin/sendmail -f "user1@daemon.com" user2@daemon.com <hi.txt

The contents of the hi.txt will be sent as the body of the message..

Please help..... Thanks in advance..

Madhu

There is no simple oneliner for doing this. The classic UNIX way would be to uuencode the tarball and embed it as part of your message. There are however a number of ways of building a message with an attachment.

The following should work if your version of uuencode supports the -m option (but I have no tested it!)

(cat hi.txt ; uuencode -m file.tar tarball) | sendmail -f "user1@daemon.com"

Here are a couple of pointers:

Mailing Attachments from UNIX
Sending email with a text message and an attachment from standard UNIX.