PDA

View Full Version : email notification of backup logs..



Mia_tech
December 6th, 2008, 01:13 AM
guys I have a script that backsup my home folder and I would like to add a mail command that emails me the logs after backup is done... could anyone suggest a simple way of doing this?...

thanks

slavik
December 6th, 2008, 01:14 AM
I think sendmail can be used as a simple command line mail program :)

EDIT: nvm, just tried the above, it didn't work ...

ghostdog74
December 6th, 2008, 01:20 AM
mailx -s "test" root < file

Mia_tech
December 6th, 2008, 01:24 AM
mailx -s "test" root < file


yes.. but I actually need that msg to go out to a real smtp server and be delivered to my email address.... I type mailx --help but I see no settings for specifying mail server, email address etc..

ghostdog74
December 6th, 2008, 01:30 AM
I think sendmail can be used as a simple command line mail program :)

EDIT: nvm, just tried the above, it didn't work ...

it should work, most simplistically


sendmail root < file

otherwise, you need to check your sendmail setup.

slavik
December 6th, 2008, 01:32 AM
slavik@slavik-desktop:~$ sendmail
Exim is a Mail Transfer Agent. It is normally called by Mail User Agents,
not directly from a shell command line. Options and/or arguments control
what it does when called. For a list of options, see the Exim documentation.
slavik@slavik-desktop:~$

ghostdog74
December 6th, 2008, 01:33 AM
yes.. but I actually need that msg to go out to a real smtp server and be delivered to my email address.... I type mailx --help but I see no settings for specifying mail server, email address etc..
mailx is a client. if you are sending emails internally in your network, you should setup your MTA properly. Check your sendmail documents. Otherwise, you should have no problem sending out emails to the internet

ghostdog74
December 6th, 2008, 01:39 AM
slavik@slavik-desktop:~$ sendmail
Exim is a Mail Transfer Agent. It is normally called by Mail User Agents,
not directly from a shell command line. Options and/or arguments control
what it does when called. For a list of options, see the Exim documentation.
slavik@slavik-desktop:~$


you are using Exim as MTA, while i don't have Exim. I only have sendmail. So you should probably use something like


exim <options>

and not


sendmail <options>

unless maybe you have some aliases.

Reference (http://www.exim.org/exim-html-3.20/doc/html/spec_5.html)

psusi
December 6th, 2008, 03:03 AM
If you have cron run the backup script, it mails you the output of jobs by default. You just need to install and configure a mail server to get it.

Mia_tech
December 6th, 2008, 04:34 AM
guys I just need a simple smtp mailer application...... who can send mail to my mail server out on the internet like eg: mail.google.com NOte: don't send mail to that server it is just an example"... and in turn that server would relay the email to the appropiate address.. maybe I'm just thinking windows here... but there is a ton of smtp mailer application in windows like "sendmail", "mailsend", "blat" etc.. that you can script, and I"m looking to do the same in ubuntu without installing any services like mail servers, postfix or what have you...

mssever
December 6th, 2008, 06:34 AM
I"m looking to do the same in ubuntu without installing any services like mail servers, postfix or what have you...
That's what Postfix and friends are for. Of course, you could also use Python's excellent smtplib module and write yourself a little mailer with very little effort. Maybe one exists already, but it would be merely a special case of an MTA such as Postfix.

EDIT: Here's a (slightly-modified) code snippet from one of my projects to illustrate what I mean:

import smtplib

# snip

msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\nDate: %s\r\nContent-Type: %s\r\n\r\n%s" % (
config['email_from'],
toaddrs,
message_subject,
message_date,
"text/plain",
message_body,
)

# smtpinfo is a dictionary containing connection and message info

s = smtplib.SMTP(smtpinfo['server'], smtpinfo['port'])
if DEBUG:
s.set_debuglevel(1)
s.ehlo()
if smtpinfo['authentication']:
if smtpinfo['use_tls']:
s.starttls()
s.ehlo()
s.login(smtpinfo['login_name'], smtpinfo['password'])
result = s.sendmail(config['email_from'],toaddrs,msg)
s.quit()
if result: # This means that one or more destination addresses were unsuccessful
for i in result:
print i

Mia_tech
December 6th, 2008, 07:14 AM
wow, this has proven to be more difficult than what I thought, one of my server is running 2003 server and no sort of exchange or mail server is running, and I manage to send myself all sort of emails notifications.... and wanted to take the same approach in my ubuntu box, but I'll guess I will install postfix..

thanks all