I've created a script that runs every night on my Linux server that uses mysqldump to back up each of my MySQL databases to.
How do I send a file as an email attachment using Linux command line? - Stack Overflow
The next step I want to accomplish is to send that tar file through email to a remote email server for safekeeping. I've been able to send the raw script in the body an email by piping the backup text file to mailx like so:. While this accomplishes what I need, I think it could be one step better, Is there any way, using shell scripts or otherwise, to send the compressed.
This would beat having to deal with very long email messages which contain header data and often have word-wrapping issues etc. None of the mutt ones worked for me. It was thinking the email address was part of the attachemnt. From looking at man mailxthe mailx program does not have an option for attaching a file. You could use another program such as mutt. Unfortunately mpack does not recognize '-' as an alias for stdin.
But the following work, and can easily be wrapped in an shell alias or a script:. I use SendEmail, which was created for this scenario. It's packaged for Ubuntu so I assume it's available. You can use mutt to send the email with attachment.
If you don't have uuencode read this: Make sure you have uuencode installed and available: Make a new file called test. Change the export variables on the top of test. Check your email inbox, the text should be in HTML format and the pdf file automatically interpreted as a binary file.
Take care not to use this function more than say 15 times in a day, even if you send the emails to yourself, spam filters in gmail can blacklist a domain spewing emails without giving you an option to let them through. And you'll find this no longer works, or it only lets through the attachment, or the email doesn't come through at all.
If you have to do a lot of testing on this, spread them out over days or you'll be labelled a spammer and this function won't work any more. Not a method for sending email, but you can use an online Git server e. Bitbucket or a similar service for that.
This way, you can use git push commands, and all versions will be stored in a compressed and organized way. Save the received mail body as db.
One more thing about mutt: If it's not what you need, you can create alternative muttrc file containing a string like this: Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site the association bonus does not count.
Would you like to answer one of these unanswered questions instead?
Stack Overflow Questions Developer Jobs Documentation beta Tags Forex hedging strategies pdf. Sign up or log in to customize your list. Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more forex dalam islam 2014 Stack Overflow the company Business Learn more about hiring developers or posting ads with us.
Log In Sign Up. Join the Stack Overflow Community.
Stack Overflow is a community of 7. Join them; it only takes a minute: How do I send a file as an email attachment using Linux command line? I've been able to send the raw script in the body an email by piping the backup text file to mailx like so: Braiam 3, 8 29 Kit Woodstock ontario pet adoption 2, 5 22 Sorry, I haven't been doing this for a while now.
I know it involved invoking mysqldump and then attaching the output to an email with mutt. I'm using mutt 1. Worked for me using Mutt 1. Take a look at unix.
Daniel Fone 1, 1 15 This sends the uuencoded part inline and not as an attachment. Many mail-clients recognize this though and display the uuencoded part as an attachment. Don't use uuencode in this day and age. MIME is slightly more complex but a lot more user-friendly. None of them use mail! Chris N 6 7.
That did the trick, I was having trouble getting mutt to do the action silently. See answer below stackoverflow. Depending on your version of linux it may be called mail. To quote David above: How about the other option? Nathan, it looks like your quote from David is wrong - he used the mutt command, not how to get bonus without attachment to binary options. Also as others have pointed out, mutt now seems to require a -- argument before the address.
But the following work, and can easily be wrapped in an shell alias or a script: This worked for me as well.
This could work in bash for stdin. I don't have mpack, so I have not tried: It's packaged for Ubuntu so I assume it's available sendemail -f sender some. Fredrik Wendt 4 I believe, it should be "sendEmail" instead of "sendemail" in your example.
Skynet 3, 5 18 Sourabh Potnis 1 6 Uses default mailx and works perfectly. I was looking for something which works in EC2 and this worked fine. You can use mutt to send the email with attachment mutt -s "Backup" -a mysqldbbackup.
David Schlosnagle 3, 1 15 I once wrote this function for ksh on Solaris uses Perl for base64 encoding: Send a Plaintext body email with one plaintext attachment with mailx: Make sure you have ksh installed: Gunstick 4 3. Allan Pinto 86 1 1 9.
I believe there are two implementations. On one -a is for attachments, on the other it is for headers. The version of mailx in Ubuntu comes from GNU and there -a means add a header. I usually only use the mail command on RHEL. I have tried mailx and it is pretty efficient.
Alejandro Santillan 11 1. Philippe Gachoud 9 Just to add my 2 cents, I'd write my own PHP Script: Mike Graf 2, 26 If you really want to go down the "write your own script" path, then perl or python are much better suited as they are usually available by default. Ben-Uri 3, 1 24 This is how I am doing with one large log file in CentOS: The message content will be taken from text file below echo 'Hello!
Same for me - looks like the syntax of Mutt may have changed. Doesn't work for me at all. This should be the accepted answer.
At least as of mutt 1. For me it worked the other way round. Not every server may have PHP installed. MathOverflow Mathematics Cross Validated stats Theoretical Computer Science Physics Chemistry Biology Computer Science Philosophy more 3. Meta Stack Exchange Stack Apps Area 51 Stack Overflow Talent.