You are not logged in.

#1 2010-09-09 21:36:56

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

[Almost Completed] Using Mailx to send output of rsync backup

I'm sure this is very simple.

I run an rsync to backup my machines as a cron job weekly.

I would quite like to be able to see the output of that in a log file and I would also like to be able to have a log file if I manually invoke the backup.

Also when the backup is done I would like it to send me an email stating that, with the logfile attached.

I'm not sure how to do the first part but I'm sure the email could be achieved through sendmail but I'm not sure how to add an attachment with that.

Any help extremely appreciated.

Last edited by llawwehttam (2010-09-09 23:19:58)

Offline

#2 2010-09-09 21:45:16

marxav
Member
From: Gatineau, PQ, Canada
Registered: 2006-09-24
Posts: 386

Re: [Almost Completed] Using Mailx to send output of rsync backup

mailx -s [YourSubject] -a [PathToYourAttachment] you@somewhere.

Offline

#3 2010-09-09 21:46:28

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

Re: [Almost Completed] Using Mailx to send output of rsync backup

Thanks a bunch. Done some more looking into the first part.

Would this work?

bash$ rsync -avzuh user@computertobackup:~/ /mnt/backups > "/mnt/backups/backuplog-`date +"%m-%d-%y`"

Offline

#4 2010-09-09 21:49:03

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Almost Completed] Using Mailx to send output of rsync backup

marxav wrote:

mailx -s [YourSubject] -a [PathToYourAttachment] you@somewhere.

You can also add some extra info in the body of the message

echo "Done" | mailx -s subject -a attachement login@host

Offline

#5 2010-09-09 21:50:19

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

Re: [Almost Completed] Using Mailx to send output of rsync backup

Thanks. I'll see what I can come up with and post the result to make sure it'll work.

Offline

#6 2010-09-09 22:03:56

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

Re: [Almost Completed] Using Mailx to send output of rsync backup

I have mailx installed but typing mailx in a terminal gives: /usr/sbin/sendmail no such file or directory

I have looked at a lot of tutorials for setting up sendmail but most of them compile from source and are used for mail servers.

Any advice?

Offline

#7 2010-09-09 22:04:44

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Almost Completed] Using Mailx to send output of rsync backup

set sendmail="/usr/bin/mailx"

Offline

#8 2010-09-09 22:11:07

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

Re: [Almost Completed] Using Mailx to send output of rsync backup

karol wrote:

set sendmail="/usr/bin/mailx"

Thanks. I didn't see your old post on this when I searched.

karol wrote:

> I am guessing this is a newer version of the same mailx?
It's a bit ore complicated http://heirloom.sourceforge.net/mailx.html

Do you have sendmail installed?

I had a problem like this too.
http://bbs.archlinux.org/viewtopic.php? … 80#p765580

Run

ln -s /usr/bin/mailx /usr/sbin/sendmail

and try again.

Offline

#9 2010-09-09 22:12:14

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Almost Completed] Using Mailx to send output of rsync backup

The 'set' command is better than using symlinks ;P

Offline

#10 2010-09-09 22:15:00

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

Re: [Almost Completed] Using Mailx to send output of rsync backup

Thanks. I guess symlinks can create conflicts then.

I'm just really getting into linux. Been using it 6 years and have only scraped the surface. XD

Offline

#11 2010-09-09 22:21:09

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

Re: [Almost Completed] Using Mailx to send output of rsync backup

As /usr/bin/mailx didn't exist I assumed that it is now /usr/bin/mail which exists.

However set sendmail="/usr/bin/mail" had no affect on the output.

Offline

#12 2010-09-09 22:23:56

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Almost Completed] Using Mailx to send output of rsync backup

I'm using mailx-heirloom, not mailx - don't know if that makes a difference or not.

I think you need to configure it.

[karol@black ~]$ cat /etc/nail.rc 
set sendmail="/usr/bin/mailx"

set smtp=smtp.gmail.com:587
set smtp-use-starttls
set ssl-verify=ignore
set ssl-auth=login
set smtp-auth-user=login@host
set smtp-auth-password=PASSWORD

I'm using it with my gmail account.

As I wrote in the old post you've found, it's a bit complicated (the mailx / mailx-heirloom thing).

Last edited by karol (2010-09-09 22:28:31)

Offline

#13 2010-09-09 22:47:56

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

Re: [Almost Completed] Using Mailx to send output of rsync backup

Installed mailx-heirloom as it seems more people use it.

Set up the config file but on typing the command:

echo "test" | mailx -s "testing" user@host.com

I get:

usr/sbin/sendmail: No such file or directory
"/home/user/dead.letter" 8/218
. . . message not sent.


Any ideas?

Offline

#14 2010-09-09 22:51:58

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Almost Completed] Using Mailx to send output of rsync backup

llawwehttam wrote:

Installed mailx-heirloom as it seems more people use it.

Set up the config file but on typing the command:

echo "test" | mailx -s "testing" user@host.com

I get:

usr/sbin/sendmail: No such file or directory
"/home/user/dead.letter" 8/218
. . . message not sent.


Any ideas?

Are you sure it's 'nail.rc'?
I'm using that nail.rc config I posted and I'm fine.

You can try 'ln -s /usr/bin/mailx /usr/sbin/sendmail' if nothing else works.

Last edited by karol (2010-09-09 22:53:38)

Offline

#15 2010-09-09 23:01:10

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

Re: [Almost Completed] Using Mailx to send output of rsync backup

I had got the port wrong but now I have a nice new error:

smtp-server: Ip-ad-dr-ess <myusername@localhost.localdomain>:sender address not owned by user myuser@host.com

I guess I have to get mailx to send it as myusername@host.com instead of @localhost.localdomain but how do I do that?

Offline

#16 2010-09-09 23:11:43

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Almost Completed] Using Mailx to send output of rsync backup

llawwehttam wrote:

I had got the port wrong but now I have a nice new error:

smtp-server: Ip-ad-dr-ess <myusername@localhost.localdomain>:sender address not owned by user myuser@host.com

I guess I have to get mailx to send it as myusername@host.com instead of @localhost.localdomain but how do I do that?

I'm using it to e-mail things to myself - I think you're trying to do exactly that, so it should work.
I've been using it with gmail only, so I don't know if and how it works for other providers.
I don't recall making any additional configurations and I've never been presented with an error like yours.

set smtp-auth-user=MY.LOGIN@gmail.com
set smtp-auth-password=PASSWORD

I have my real login and password there and it just works.

Offline

#17 2010-09-09 23:14:02

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

Re: [Almost Completed] Using Mailx to send output of rsync backup

Interesting. I will try with a gmail address to see if it makes a difference.

Offline

#18 2010-09-09 23:14:45

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [Almost Completed] Using Mailx to send output of rsync backup

Moved to Newbie Corner - and you might want to reword the post title to focus on your mailx issue: it will attract a little more focused scrutiny that way...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#19 2010-09-09 23:19:01

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

Re: [Almost Completed] Using Mailx to send output of rsync backup

IT LIVES!!!!!!

The best email I have ever recieved:

Subject : testing

Test



Is that a bit sad?

Anyway I am integrating it into a script now.

Will post it when done.


Thanks for all the help.

Offline

#20 2010-09-10 10:52:49

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

Re: [Almost Completed] Using Mailx to send output of rsync backup

I'm sure this could be much refined but here's what I've got:

(Its to be manually invoked for now but I will set a modified version as a cron when I get some more hard drive space.)

#!/bin/bash
DATE=`date +%m-%d-%y`
echo -n "What directory do you want to back up? : "
read DIRECTORY
rsync -avzuh Targetmachine:~/$DIRECTORY . > /home/username/logs/backup-log-$DIRECTORY-$DATE.txt &&
echo "Backup of $DIRECTORY Complete, Log attached" | mailx -s "Backup Complete" -a "/home/username/logs/backup-log-$DIRECTORY-$DATE.txt" user@HOST

This means I can leave DIRECTORY blank, which would backup the entire home folder, but I don't need to.

I usually keep a track of what I've saved in the week so I can just backup the folders that I feel need it.

Offline

#21 2010-09-10 11:55:40

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Almost Completed] Using Mailx to send output of rsync backup

As you're using 'u' option in rsync, you can backup the whole ~ folder and let rsync do the work. If you don';t need something, you can exclude it.

Offline

#22 2010-09-10 11:57:03

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

Re: [Almost Completed] Using Mailx to send output of rsync backup

Thanks. How would I exclude all files beginning with . ?

Offline

#23 2010-09-10 12:47:21

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Almost Completed] Using Mailx to send output of rsync backup

llawwehttam wrote:

Thanks. How would I exclude all files beginning with . ?

rsync -avuzb --exclude '.*'

seems to work.

Offline

#24 2010-09-10 12:48:20

llawwehttam
Member
From: United Kingdom
Registered: 2010-01-19
Posts: 181

Re: [Almost Completed] Using Mailx to send output of rsync backup

Thanks. Will use that.

Offline

Board footer

Powered by FluxBB