How to send notifications for RCLONE


#1

I have an entire tutorial to do this, but since I am a new user in the forums, the system wouldn’t allow me to post more than 2 links and no more than a picture.


#2

love to see this here.


#3

RClone does not have built in notifications, however you can configure a script to send an email notification (When installed on Windows) and setup a task to do it automatically.

RClone generates logs in a raw TXT file, so the first thing is convert it into an HTML file to send it later using powershell.

To generate the log file when running RClone use something like this:

rclone sync "C:\Test" remote:Test --log-file "C:\Program Files\RCLONE-v1.39\Logs\logs.txt" --stats-log-level NOTICE

In this example I am syncing Test folder on my C drive to a Remote previously configured (Look for the conf how to in RClone Documents) and I use the log file option to write the logs in the directory where I have my folder of RClone.

After this we are going to create a new powershell Script. Open powershell and create a new script like this:

#######################Convert Logs to HTML#######################_
CD "C:\Program Files\RCLONE-v1.39\Logs"
$SourceFile = "C:\Program Files\RCLONE-v1.39\Logs\logs.txt"
$TargetFile = "C:\Program Files\RCLONE-v1.39\Logs\logs.htm"
$File = Get-Content $SourceFile
$FileLine = @()
Foreach ($Line in $File) {
 $MyObject = New-Object -TypeName PSObject
 Add-Member -InputObject $MyObject -Type NoteProperty -Name "PUT YOUR TITLE HERE" -Value $Line
 $FileLine += $MyObject
}
$FileLine | ConvertTo-Html -Property "YOUR TITLE" -body "`<H2>YOUR SUBTITLE</H2>`" | Out-File $TargetFile
###############################################

Next, we are going to define the variable for the email server:
In the same powershell script type this below the previous one (example with gmail):

####################Define Variables for email####################
$fromaddress = "YOUR-EMAIL@gmail.com"
$toaddress = "TO-ADDRESS@diamedca.net"
$CCaddress = ""
$BCCaddress = ""
$Subject = "YOUR EMAIL SUBJECT"
$body = get-content .\logs.htm
$attachment = "C:\Program Files\RCLONE-v1.39\Logs\logs.txt"
$smtpserver = "smtp.gmail.com"
##################################################################

Next, the script to send the message:

##################################################################
$message = new-object System.Net.Mail.MailMessage
$message.From = $fromaddress
$message.To.Add($toaddress)
#$message.CC.Add($CCaddress) --> Take out the number sign if you have cc address
#$message.BCC.Add($BCCaddress) --> same as previuos
$message.IsBodyHtml = $True
$message.Subject = $Subject
#$attach = new-object Net.Mail.Attachment($attachment) --> Option to send attachment
#$message.Attachments.Add($attach) --> not used in this example
$message.body = $body
$smtp = new-object Net.Mail.SmtpClient($smtpserver, 587)
$smtp.EnableSsl = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential(“YOUR-EMAIL@gmail.com”, “YOUR-PASSWORD”);
$smtp.Send($message)
##################################################################

Next, delete the html file and rename the log file to keep the logs in the folder:

##################################################################
remove-item .\logs.htm
Rename-Item logs.txt "Logs $(Get-Date -UFormat "%Y-%m-%d").txt"
##################################################################

Now all you have to do is configure a windows task to execute the powershell script after the Sync is completed.
To do that, let’s create the first task:
I created a .bat file to run RClone. I saved the .bat file inside the RClone Folder. The file contains the following script:

#########################################
cd "C:\Program Files\RCLONE-v1.39"
rclone sync "C:\test" remote:test --log-file "C:\Program Files\RCLONE-v1.39\Logs\logs.txt" --stats-log-level NOTICE
#########################################

After that, open task Scheduler and create a task.
Name the task RCLONE-SYNC, and configure the action, start a program, executing the .bat file:
Actions: Start a Program
Details: c:\Prgram Files\RClone\Sync.bat (This is an example, use your path)

In security options select the following:
Run whether user is logged on or not
Run with highest privileges
(Its is going to ask you for the user password and store it)

And in triggers, configure the schedule time to run your task:
Trigger: Daily
Detail: At 3 am every day, enabled.

Also, here are the conditions and settings I set up:
Only checked:
- Wake up computer to run this task.
- Allow task to be run on demand
- Run task as soon as possible after schedule task is missed

Now, create a new task and name it RClone-Email-Notification, with the following action:
Action: Start a Program
Program: powershell.exe
Add arguments: .\EmailScript.ps1
Start in: C:\Program Files\RClone
This will run our powershell email script (Use all the commands explained before to create your .ps1 file using powershell, name and save the file in your RClone directory and use the path for the “start in” in the task you create.

Now, the trigger is the most difficult part, we want to configure the task to trigger after the Sync task finishes, to do that use the following config:

Edit Event Filter:
- Edit query manually:

<QueryList>
  <Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational">
    <Select Path="Microsoft-Windows-TaskScheduler/Operational">*[EventData
[@Name='TaskSuccessEvent'][Data[@Name='TaskName']='\RCLONE-SYNC']]</Select>
  </Query>
</QueryList>

Save it and run your sync!


#4

I just use mailsend to send the TXT log files after the sync command in scripts.

Much easier …


#5

Nice!
I never found an easier way.
Can you explain a little bit more how to use that mailsend command? Is that a new feature among the RClone options?


#6

No, no, it’s another tool: https://github.com/muquit/mailsend.

The syntax is very similar to what you posted above:

mailsend^
 -to "ioioio@ioioio.com"^
 -from "ioioio@ioioiol.com"^
 -starttls^
 -port 587^
 -auth^
 -smtp "smtp.ioioio.com"^
 -sub %subject%^
 -user "ioioiol@ioioiol.com"^
 -pass "ioioio"^
 -mime-type "text/plain"^
 -msg-body "logfile.txt"

The “^” is because I’m using windows.