Results of Rsync Task via email

Status
Not open for further replies.

m3ki

Contributor
Joined
Jun 20, 2016
Messages
118
I have couple of questions regarding rsync tasks.

I have an rsync task running nightly.

Question 1.
If the rsync task takes longer than 2 days. Will I have 2 tasks running concurrently the next day? or is there a lock mechanism?

Quesiont 2.
How would I go about sending me report of the execution of the task?
I would like to see if there are any errors or if there was a success? (I know how to check /var/log/messages, and I don't want to do this I want simplicity and automation)
I didn't see anything in daily output email. What is the best practice in this regard? Simple email similar to daily cron output would be perfect.

Thank you
 

Sakuru

Guru
Joined
Nov 20, 2015
Messages
527
#2
You can use sendmail if you have configured your email settings under System --> Email.
Code:
#!/bin/bash
echo -e "Subject:Test Subject\nTest Body" | sendmail user@domain
 

m3ki

Contributor
Joined
Jun 20, 2016
Messages
118
#2
You can use sendmail if you have configured your email settings under System --> Email.
Code:
#!/bin/bash
echo -e "Subject:Test Subject\nTest Body" | sendmail user@domain


Thank you for the prompt reply.
I get what you're saying regarding piping message to sendmail.

What about getting that log of a command into email, am I supposed to be grepping the var/log/messages into it ?
 

m3ki

Contributor
Joined
Jun 20, 2016
Messages
118
Thank you for the prompt reply.
I get what you're saying regarding piping message to sendmail.

What about getting that log of a command into email, am I supposed to be grepping the var/log/messages into it ?


Also, this means I can't be using built in rsync gui module right?
 

Sakuru

Guru
Joined
Nov 20, 2015
Messages
527
OH! You're using the actual rsync task. I thought you were setting up a cron job. I've never used the rsync task, so I don't know how it handles logging.

If you use a cron job you can save the output of commands into variables. This is best if you have multiple commands.
Code:
#!/bin/bash
output=$(rsync -option1 -option2 source destination 2>&1)
output+=$(something else)
echo $output | sendmail user@domain


If you have a single command you can just pipe it straight to sendmail.
Code:
#!/bin/bash
rsync -option1 -option2 source destination 2>&1 | sendmail user@domain


The 2>&1 means "Redirect all errors to stdout". That way you get standard output and errors.
 

m3ki

Contributor
Joined
Jun 20, 2016
Messages
118
OH! You're using the actual rsync task. I thought you were setting up a cron job. I've never used the rsync task, so I don't know how it handles logging.

If you use a cron job you can save the output of commands into variables. This is best if you have multiple commands.
Code:
#!/bin/bash
output=$(rsync -option1 -option2 source destination 2>&1)
output+=$(something else)
echo $output | sendmail user@domain


If you have a single command you can just pipe it straight to sendmail.
Code:
#!/bin/bash
rsync -option1 -option2 source destination 2>&1 | sendmail user@domain


The 2>&1 means "Redirect all errors to stdout". That way you get standard output and errors.


Thanks for the info! I am a dev this can get me started :)

I was hoping for a "whitebox" solution but oh well back to writing scripts :D
 

pixel8383

Explorer
Joined
Apr 19, 2018
Messages
80
OH! You're using the actual rsync task. I thought you were setting up a cron job. I've never used the rsync task, so I don't know how it handles logging.

If you use a cron job you can save the output of commands into variables. This is best if you have multiple commands.
Code:
#!/bin/bash
output=$(rsync -option1 -option2 source destination 2>&1)
output+=$(something else)
echo $output | sendmail user@domain


If you have a single command you can just pipe it straight to sendmail.
Code:
#!/bin/bash
rsync -option1 -option2 source destination 2>&1 | sendmail user@domain


The 2>&1 means "Redirect all errors to stdout". That way you get standard output and errors.
Hello Sakuru, I just discover your solution. I was using something similar with an rclone task. Unfortunately when I nest the command inside $(...) the cron task fails. I posted it here. Do you have any suggestion?
Thanks,
Emanuele
 
Status
Not open for further replies.
Top