Discuss new features and functions
Zenju
Posts: 4955
Joined: 9 Dec 2007
A user sent me a script which may be useful for admins who want to run FreeFileSync and send a status report via email:

>I needed email notification containing log warnings and errors, so I wrote the attached VBS. It is probably not bug-free as I could test it only in my environment, but you are welcome to it. If it's something you would like to distribute to add value to your product, fell free to do so.
Again, thank you.
Lane Beneke
You do not have the required permissions to view the files attached to this post.

nodough
Posts: 10
Joined: 17 Sep 2013
Hi All,

I've updated this script several times and thought it might be a good idea to upload the updated version.

Enjoy,
NoDough

Edit: Attachment removed in favor of newer version below.
You do not have the required permissions to view the files attached to this post.

eahm
Posts: 16
Joined: 13 Apr 2014
Hi, thank you for this. Few questions:

1) Do I have to put this file on "On completion:"? Just exactly like a .bat file?

2) Do I have to create multiple copies based on how many profiles I have? With different names?

3) How can I use it with the Gmail SMTP (SSL, Auth etc.)?

Thank again.
You do not have the required permissions to view the files attached to this post.

nodough
Posts: 10
Joined: 17 Sep 2013
Hello All,

Posting yet another update to the script. The most obvious change is I've added duration to the report.

1) The script will execute FreeFileSync.exe and wait for it to terminate. How it terminates is up to you, but the script will not continue until it does.

2) I like to divide my ffs_batch files up according to their task. But there's no reason you couldn't dump all your tasks into a single ffs_batch file.

3) Good question. I have no idea. But this site appears to guide you through it.

Enjoy!

Edit: Removed file attachment in favor of newer version below.
Last edited by nodough on 07 Apr 2016, 16:06, edited 1 time in total.

berettatim
Posts: 1
Joined: 10 Nov 2014
If for someone could help....
You could update the script to send email with more paramenters of authentication, I found this:

Const SMTPServer = "yourserver.yourdomain.com"
Const SMTPAuth = 1
Const SMTPPort = 25

oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = SMTPAuth
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPPort
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'SendUsingPort

Dim ArgArray(10,1)

ArgArray(6,0) = "SMTPServer"
ArgArray(6,1) = "oMsg.Configuration.Fields.Item(""http://schemas.microsoft.com/cdo/configuration/smtpserver"")"
ArgArray(7,0) = "SMTPAuth"
ArgArray(7,1) = "oMsg.Configuration.Fields.Item(""http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"")"
ArgArray(8,0) = "SMTPPort"
ArgArray(8,1) = "oMsg.Configuration.Fields.Item(""http://schemas.microsoft.com/cdo/configuration/smtpserverport"")"
You do not have the required permissions to view the files attached to this post.

teymur-bagirov
Posts: 2
Joined: 14 Nov 2015
we use blat (command line smtp sender)
the next line in bat file after FFS is blat, which sends log.
that's it
You do not have the required permissions to view the files attached to this post.

nodough
Posts: 10
Joined: 17 Sep 2013
I've updated the script and attached it to this message. Updates include...

Added the fields for SMTP authentication.
Modified the Email send process to retry on failure.
Fixed bug finding log files.
Fixed bug calculating elapsed time.
Added server name and batch name to body of report.

NoDough

P.S.: Two users have inquired how to send the entire log file. This script is not designed to send the entire log file. The purpose of this script is to send only the errors and warnings when things go wrong.
You do not have the required permissions to view the files attached to this post.

FileSyncExpert
Posts: 11
Joined: 31 Mar 2016
Thanks for sharing this. I worked on an similar Project with autohotkey. Its a beta Version.
When its done, i will share this to... I hope that it does not take longer than 2 - 3 Weeks...

hughc
Posts: 2
Joined: 13 Apr 2016
great script!

I modified it slightly to work with gmail as the SMTP provider, as SSL is required; adding an SSL param was not difficult, but I did not bother to expose it as a command line argument (for my end use) just a configuration constant:

Code: Select all

Const SMTPSsl = 1
...
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = SMTPSsl

Hope that might help anyone making use.

As an aside, if you set up a dummy gmail account just for the purposes of sending the mail, you will need to enable the 'Less Secure Apps setting in order that mail be sent.

cheers,
Hugh

JonBenavides
Posts: 1
Joined: 9 Jun 2016
it is possible to attach the last log file in email?

timberetta
Posts: 5
Joined: 29 Apr 2016
Is it possible to insert in the subject the tag [Warning] or [Error] if the exiterror code is it?
Pls anyone could help?
Thank you.

serendipityguy
Posts: 23
Joined: 9 Aug 2016
JonBenavides wrote: it is possible to attach the last log file in email?
I guess that some of the log files are too large for email depending on the size of your backup disk.

serendipityguy
Posts: 23
Joined: 9 Aug 2016
Zenju wrote: A user sent me a script which may be useful for admins who want to run FreeFileSync and send a status report via email:
Lane Beneke
Could this be added into the next build as a feature request? Thanks for sharing Lane.

TheExpert
Posts: 31
Joined: 13 Aug 2018
Hi all,

because of a change in the FFS batch files regarding the tags for log folder you have to replace the search string in the VBS script to find the log folder. If you don't change it you get mail notifications with the following line at the end of the mail "No log file is configured for this batch.".

Instead of the code "If InStr( sLine, "LogfileFolder" ) Then 'FIND LINE CONTAINING LOG FILE FOLDER"
you have to set "If InStr( sLine, "LogFolder" ) Then 'FIND LINE CONTAINING LOG FILE FOLDER".

Update 23 Aug 2018: There were some errors with the log file handling and with the search strings for errors or warnings which I have fixed now. You can choose between German and English error / warning search strings in the section for configuring the script settings. If there are errors or warnings in the log file the lines with the errors or warnings are now added to the notification mail as it was originally designed by Lane Beneke.

Update 08 Sep 2018: I found a new bug in the VBS script. Sometimes the script checked the wrong log file. This is possible if there is more than one job running at the same time. So I've uploaded a new version of the script with the bugfix.

Update 22 Oct 2018: There's now an option to define the path to another GlobalSettings.xml or similar named file.

Update 19 Nov 2018: Because of an error when there's no GlobalSettings.xml or similar named file defined I added a check for ConstGlobalSettingsFile: If it isn‘t defined the call procedure of FreeFileSync will be changed. And thanks to @timberetta I added the option for a SSL secured SMTP connection. I don't have the possibility to test the SSL encryption for the SMTP connection. Maybe someone else can test it and give feedback if this is working?

Update 26 Feb 2019: There was an error with parsing the command line when setting a GlobalSettings.xml or similar named file as parameter. Added the description of the new command line parameters 'SMTPSsl' and 'GlobalSettingsFile' to the usage manual at the beginning of the script.

You'll find the modified script in the attachment.

Kind Regards

TheExpert
You do not have the required permissions to view the files attached to this post.
Last edited by TheExpert on 26 Feb 2019, 07:25, edited 10 times in total.

Zenju
Posts: 4955
Joined: 9 Dec 2007
What about using FreeFileSync's "On completion" to send the email and evaluating "%logfile_path%"?

TheExpert
Posts: 31
Joined: 13 Aug 2018
Hi Zenju,

Can FreeFileSync now send mail notifications, too? For about more than a year this feature wasn't available. So I have to use the VBS script to get mail notifications.

Kind Regards

TheExpert

Rechotech
Posts: 1
Joined: 25 Oct 2018
@The Expert

I have been unable to get the most current script tor run i get an error message

Cannot find file"".

followed by windows script host message

C:\backup_scripts\FreeFileSync.vbs
line 469
Char 4
Error Invalid procedure coll or argument 'Mid'
code 800A0005

Any ideas.

TheExpert
Posts: 31
Joined: 13 Aug 2018
Rechotech wrote:
25 Oct 2018, 15:36
@The Expert

I have been unable to get the most current script tor run i get an error message

Cannot find file"".

followed by windows script host message

C:\backup_scripts\FreeFileSync.vbs
line 469
Char 4
Error Invalid procedure coll or argument 'Mid'
code 800A0005

Any ideas.
The issue with the line and char information in the error message is that these don't correspond to the lines and chars in the script. So it's not very easy to find the error.

Have you defined the path to the log files of your sync / backup jobs at the beginning of the script? Have you saved the job files with the option to save the log file to the same location as defined in the script? The script doesn't search for the file LastSync.log. It searches for log files named like the job with the suffix of the timestamp. And if there are more than one files it looks for the timestamp of the file.

Maybe it will help you to set the option DoDebug = True at the beginning of the script. This will show you a lot of windows with the variables set by the script during the run.

sagitario
Posts: 8
Joined: 8 Nov 2018
Hi,
I have the same error.
After some tests I find out the problem.
"Cannot find file "".

This is regarding the GlobalSettings. I put the default full path and the error message disappear. For some reason leaving blank don't work.

Code: Select all

Const GlobalSettingsFile = "%appdata%\FreeFileSync\GlobalSettings.xml" 
The second error Is regarding the log file. For some reason it can't find/read the log file. In the "Const BatchFile = " I put the full path to file instead the batchfile name only. Changing this and the error disappear and the script work like a charm.

Regards,

PS: The "log file search strings" need to be change to the current language that is use.

TheExpert
Posts: 31
Joined: 13 Aug 2018
OK, I will insert a check for ConstGlobalSettingsFile: If it isn‘t defined the call procedure of FreeFileSync has to be changed.

You can define the batch file as command line parameter. So there‘s no need to set the ConstBatchFile in the script. With the command line parameter you are able to use different batch files for your synchronisation jobs - if needed.

sagitario
Posts: 8
Joined: 8 Nov 2018
Define the batch file as command line parameter so there‘s no need to set the ConstBatchFile in the script is a good idea. Can you put a example how to execute the command?

By the way, if you are changing the script, can you add the SSL/TLS authentication?

Thank you for good job with this script.

TheExpert
Posts: 31
Joined: 13 Aug 2018
Thank you.

Please have look at the first lines of the script, where Lars Beneke as originator of this script described the usage:

' Usage: cscript.exe FreeFileSync.vbs <hideconsole true|false>
' <exefile d:\path\to\freefilesync.exe>
' <batchfile d:\path\to\batch.ffs_batch>
' <msgsubject "Message Subject for BatchName">
' <msgto recipient@somedomain.tld>
' <msgfrom sender@somedomain.tld>
' <smtpserver smtp.somedomain.tld | n.n.n.n>
' <smtpport nn>
' <smtpauth 0|1|2>
'
' Notes: 1) Parameter/Value pairs can be specified at the
' command line, or changed in code below. Command
' line values override coded values.
' 2) If the word "BatchName" (case sensitive) is in the
' subject line, it will be replaced by the name of
' the batch file less path and extension.

Sorry, I'm not able to implement the SSL/TLS authentication because I don't have enough experience with Visual Basic Script to do this. Do you need this feature for the authentication with the mail server? Feel free to add this on your own or maybe there's someone else in this community who can help?

sagitario
Posts: 8
Joined: 8 Nov 2018
Yeh... stupid question I know. I already read that but never put it working well... it return all the time a script error regarding the reading log file. But I understand now that the problem is regarding the batchfile path. Putting the command batch script in a different folder where the vbscript is, need to put de full path to BatchFile and doing this the reading log error came across.

I'm just curious, I do not know this type of programming very well.

For now I sending through a old mailserver that still don't ask for SSL encryption, but is a question of time so that all mailservers only accept secure connections.

Regards,

timberetta
Posts: 5
Joined: 29 Apr 2016
TheExpert wrote:
09 Nov 2018, 14:17

Sorry, I'm not able to implement the SSL/TLS authentication because I don't have enough experience with Visual Basic Script to do this. Do you need this feature for the authentication with the mail server? Feel free to add this on your own or maybe there's someone else in this community who can help?

This is the line to add/modify to implement SSL authentication (TLS is not possible in cdo):
(modify in date 10/11/18 because I left one row for mistake the following code is corrected)

' SMTPAuth 0=off, 1=clear text, 2=NTLM. IF YOU SET THIS
' TO 1, THEN YOU MUST ALSO SET THE SMTPUSERNAME AND
' Use SSL for the connection (False or True)
Const SMTPAuth = 0
Const SMTPPort = 25
Const SMTPssl = False
' THE SCRIPT WILL ATTEMPT TO SEND THE MESSAGE MaxEmailSendAttempts
' TIMES BEFORE GIVING UP. IF THE MESSAGE FAILS TO SEND, THE
' SCRIPT WILL SET THE DOS ERRORLEVEL TO 1 UPON EXIT.
Const MaxEmailSendAttempts = 10
Const SleepSecondsBeforeRetryingEmailSend = 301
' DoDebug CAUSES DIAGNOSTIC OUTPUT TO BE WRITTEN TO THE
' CONSOLE. NOTE THAT WSCRIPT.EXE USES DIALOG BOXES FOR
' OUTPUT. SO USE CSCRIPT.EXE WHEN DODEBUG IS TRUE.
Const DoDebug = False
' IF DODEBUG IS TRUE, AND THE SHELL IS EXECUTED FROM A SCHEDULE
' OR SOME OTHER PROCESS, THEN THE VALUE BELOW WILL DELAY CLOSING
' OF THE WINDOW SO YOU CAN EXAMINE THE DEBUG OUTPUT.
Const SleepSecondsBeforeClosingShell = 15
Const IncludeErrorsInReport = True
Const IncludeWarningsInReport = True
Const IncludeRuntimeStringInReport = True
Const IncludeServerNameInReport = True
' LOG FILE SEARCH STRINGS, LANGUAGE BASED
' PLEASE SELECT THE CORRESPONDING STRINGS
' GERMAN
'Const sLogFileError = "] Fehler:"
'Const sLogFileWarning = "] Warnung:"
'Const sLogFileSeriousError = "] Schwerer Fehler:"
' ENGLISH
Const sLogFileError = "] Error:"
Const sLogFileWarning = "] Warning:"
Const sLogFileSeriousError = "] Serious Error:"
'--------------------------------------------------------------

'--------------------------------------------------------------
' CHANGE NOTHING FROM THIS POINT FORWARD
Dim bHideConsole, sExeFile, sBatchFile, sGlobalSettingsFile, dtExecutionTime, dtCompletionTime
Dim oMsg, fso, sLogFile, Args, i, j, ArgTemp, ArgLen, ArgFound, ArgErrors
Set oMsg = CreateObject("CDO.Message")
Set fso = CreateObject("Scripting.FileSystemObject")

bHideConsole = HideConsole
sExeFile = ExeFile
sBatchFile = BatchFile
sGlobalSettingsFile = GlobalSettingsFile
oMsg.Subject = MsgSubject
oMsg.From = MsgFrom
oMsg.To = MsgTo
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = SMTPAuth
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPPort
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'SendUsingPort
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = SMTPssl
Const sDashedLine = "--------------------------------------------------------------"
Const sErrLogNotFound = "Unable to locate Log file for processing."
Const sErrLogNotCfgrd = "No log file is configured for this batch."
' THESE VALUES MATCH THE EXIT CODES FOR THE FreeFileSync.exe PROGRAM
Dim ExitCodeArray(3)
ExitCodeArray(0) = "Synchronization completed successfully"
ExitCodeArray(1) = "Synchronization completed with warnings"
ExitCodeArray(2) = "Synchronization completed with errors"
ExitCodeArray(3) = "Synchronization was aborted"

' PARSE THE COMMAND LINE
Dim ArgArray(11,1)
ArgArray(0,0) = "HideConsole"
ArgArray(0,1) = "bHideConsole"
ArgArray(1,0) = "ExeFile"
ArgArray(1,1) = "sExeFile"
ArgArray(2,0) = "BatchFile"
ArgArray(2,1) = "sBatchFile"
ArgArray(3,0) = "MsgSubject"
ArgArray(3,1) = "oMsg.Subject"
ArgArray(4,0) = "MsgFrom"
ArgArray(4,1) = "oMsg.From"
ArgArray(5,0) = "MsgTo"
ArgArray(5,1) = "oMsg.To"
ArgArray(6,0) = "SMTPServer"
ArgArray(6,1) = "oMsg.Configuration.Fields.Item(""http://schemas.microsoft.com/cdo/configuration/smtpserver"")"
ArgArray(7,0) = "SMTPAuth"
ArgArray(7,1) = "oMsg.Configuration.Fields.Item(""http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"")"
ArgArray(8,0) = "SMTPPort"
ArgArray(8,1) = "oMsg.Configuration.Fields.Item(""http://schemas.microsoft.com/cdo/configuration/smtpserverport"")"