You are not logged in.

#1 2008-08-15 04:58:49

colbert
Member
Registered: 2007-12-16
Posts: 809

How to have script email me when backup is done

I have a cronjob that goes like this:

5 0 * * * rsync -avzd --progress --delete --exclude '.wine/drive_c/Program\ Files' --exclude '.wine/drive_c/windows/temp' --exclude '.thumbnails' --exclude 'installs' /home/bobby/ login@website.com:backup/desktop/bobby/ >> /home/bobby/logs/webhomebackup-$(date +%m%d%y_%T).log

Now how can I have a script or some means to email myself when the backup is done?? I really have no scripting skills, hehe. TIA for any help! smile

P.S. I have mutt/getmail/procmail/sendmail/msmtp set up.

Offline

#2 2008-08-15 05:54:28

delor
Member
From: Poland
Registered: 2008-02-02
Posts: 62
Website

Re: How to have script email me when backup is done

&& mail -s "backup is done" user@hostname.ext

add something like that at the and of previous line.

Offline

#3 2008-08-15 06:09:23

tam1138
Member
Registered: 2007-09-10
Posts: 238

Re: How to have script email me when backup is done

If you change the ">>" to "tee -a" you'll get a copy of the backup log sent via e-mail, too.  (Assuming everything is configured correctly for cron to send e-mail to you.)

Offline

#4 2008-08-15 06:15:53

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: How to have script email me when backup is done

Hmm, dang I thought I had my mail setup right, but I think it's working only to receive with mutt. I just tried:

mail -v -s "testing" my@gmail.com

But it just sits there in console hanging, no output or anything. CTRL+C gives me:

^C
(Interrupt -- one more to kill letter)

Then a blitzkrieg of CTRL+C's do nothing, I just kill the window in screen. Here is my ~/.msmtprc:

# gmail
account gmail
host smtp.gmail.com
port 587
protocol smtp
auth on
from me@gmail.com
user me@gmail.com
password pass
tls on
tls_starttls on
tls_trust_file ~/.certs/Equifax_Secure_Certificate_Authority_DER.cer
account default : gmail

What could be wrong? Thanks for the help fellas smile

Offline

#5 2008-08-15 13:09:09

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: How to have script email me when backup is done

But it just sits there in console hanging, no output or anything.

When you write an email with mail/mailx the last line must finish with a dot (+ RET).

$ mail -s "Greeting" someone@host.com
Hey, I'm writing to say hello!
.


If you don't have a MTA you can setup your ~/.mailrc to relay email trough your ISP.
set smtp=mail.t-com.de


You need to install an RTFM interface.

Offline

#6 2008-08-15 15:59:52

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: How to have script email me when backup is done

Thanks anrxc, I just tried it but apparently I don't have sendmail and I couldn't find it in pacman (only perl-mail-sendmail):

~ # mail -vs "testing" me@gmail.com
testing
.
EOT
/usr/sbin/sendmail: No such file or directory
~ #

what is MTA??

Offline

#7 2008-08-15 16:07:38

afu
Member
From: Tuscalooser, Alabummer
Registered: 2004-02-19
Posts: 155

Re: How to have script email me when backup is done

MTA  is mail transport agent - in this case sendmail.  Check your logs. gmail may not accept your e-mail because the computer you are on is not a mailserver.  I.E. you don't have a MX DNS record. My experience with gmail is that it is sketchy with what it will accept and won't except.

Offline

#8 2008-08-15 16:23:13

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: How to have script email me when backup is done

Whoa, now I'm confused wink

I thought msmtp was all that was needed to send mail as I'd read on the wiki and some help guides. However above can see that I don't have any sendmail program as it is asking for.

So what do I need to do, create a mail server on my server box?? I'm a tabula rossa in this respect smile

Offline

#9 2008-08-15 16:31:55

afu
Member
From: Tuscalooser, Alabummer
Registered: 2004-02-19
Posts: 155

Re: How to have script email me when backup is done

Sendmail does not exist as a arch package. Postfix and Exim do (I think). The suggestion about sending mail via your ISP is likely the way you need to go unless you have your own domain and server - in which case you are maintaining your own DNS server.  Don't think you are. Because of SPAM, nowadays most mail servers don't accept mail from just any old box on the net.

Start by seeing is you can send mail to users on your localhost.  Example: root can send mail to user1 and user1 can reply to root.

Offline

#10 2008-08-15 16:42:54

patroclo7
Member
From: Bassano del Grappa, ITALY
Registered: 2006-01-11
Posts: 915

Re: How to have script email me when backup is done

Esmtp is a nice alternative to msmstp which is also able to pass local mail to an MDA such as procmail so that it can be delivered to other users without a full blown MTA such as postfix and sendmail.


Mortuus in anima, curam gero cutis

Offline

#11 2008-08-15 17:07:21

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: How to have script email me when backup is done

Okay so how can I send mail as root? The mail -s "subject" addy@email.com doesn't work of course, what other way do I do??

Offline

#12 2008-08-15 17:22:47

PeteMo
Member
From: H'Burg, VA
Registered: 2006-01-26
Posts: 191
Website

Re: How to have script email me when backup is done

if you have msmtp configured correctly, you can use it to send mail instead of using the 'mail' command.

Offline

#13 2008-08-15 18:05:21

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: How to have script email me when backup is done

colbert wrote:

Thanks anrxc, I just tried it but apparently I don't have sendmail and I couldn't find it in pacman (only perl-mail-sendmail):

Unfortunately Arch doesn't use heirloom's mailx by default (many distributions do). With heirloom-mailx you don't need a MTA, or a forwarder to relay mail to your ISP. Check out this package to replace mailx http://aur.archlinux.org/packages.php?ID=7924 ...if your interested (no real need since you have a forwarder/smtp client already).


You need to install an RTFM interface.

Offline

#14 2008-08-15 18:52:36

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: How to have script email me when backup is done

Dang I just tried msmtp, got this error:

~ # msmtp me@gmail.com
msmtp: cannot set X509 trust file /home/bobby/.certs/Equifax_Secure_Certificate_Authority_DER.cer for TLS session: Base64 decoding error.
msmtp: could not send mail (account default from /home/bobby/.msmtprc)
~ #

I grabbed the file from the equifax site hmm

Offline

#15 2008-08-15 19:26:49

PeteMo
Member
From: H'Burg, VA
Registered: 2006-01-26
Posts: 191
Website

Re: How to have script email me when backup is done

colbert wrote:

Dang I just tried msmtp, got this error:

~ # msmtp me@gmail.com
msmtp: cannot set X509 trust file /home/bobby/.certs/Equifax_Secure_Certificate_Authority_DER.cer for TLS session: Base64 decoding error.
msmtp: could not send mail (account default from /home/bobby/.msmtprc)
~ #

I grabbed the file from the equifax site hmm

Here's my ~/.msmtprc which works fine with gmail.  I installed ca-certificates to get the tls_trust_file.

account default
host smtp.gmail.com
protocol smtp
auth on
password *****
from user@gmail.com
user user@gmail.com
tls on
tls_starttls on
tls_certcheck on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

edit: You may need to run update-ca-certificates to generate the tls_trust_file

Last edited by PeteMo (2008-08-15 19:28:57)

Offline

#16 2008-08-15 19:45:54

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: How to have script email me when backup is done

Okay, I did the update-ca-certificates and edited my ~/.msmtprc as follows:

# gmail
account gmail
host smtp.gmail.com
port 587
protocol smtp
auth on
from me@gmail.com
user me@gmail.com
password pass
tls on
tls_starttls on
tls_certcheck on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
account default: gmail

Now I do

msmtp me@gmail.com

And I get a blank line, I type text or try that "." after a return as noted few posts up and I get nothing, it just sits there.

Offline

#17 2008-08-16 11:35:22

PeteMo
Member
From: H'Burg, VA
Registered: 2006-01-26
Posts: 191
Website

Re: How to have script email me when backup is done

You can use msmtp as a sendmail replacement for mail (the problem you were having in post #6).  Create a ~/.mailrc file and in it place

set sendmail="/usr/bin/msmtp"

.  The things suggested above should then work.

Offline

#18 2008-08-16 18:50:52

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: How to have script email me when backup is done

Okay I just did that, but still "msmtp me@gmail.com" just hangs, I try the return with a "." but nothing sad

Offline

#19 2008-08-18 21:32:21

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: How to have script email me when backup is done

Okay I don't know what's going on, but I have a few rsync backup cmds in my crontab that run at 5am every day and now when I get to the comp I see "You have new mail in /var/mail/bobby" and I can see 2 messages telling me errors in the rsync (those have been fixed hehe). Still however I'm stuck at sending mail as above sad

Offline

Board footer

Powered by FluxBB