mailsend script for FreeFileSync

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: mailsend script for FreeFileSync

#31 Post by foxidrive » 14 Apr 2014 23:41

Squashman wrote:I have seen logs where there was success and failure in the same log so your results may still not come out correctly.


eahm, does this apply to your log files? Are they generational or one off logs?

eahm
Posts: 34
Joined: 14 Apr 2014 12:49

Re: mailsend script for FreeFileSync

#32 Post by eahm » 14 Apr 2014 23:45

foxidrive wrote:eahm, does this apply to your log files? Are they generational or one off logs?

Maybe on other backup software? I haven't seen both words on the same log yet but again, these four phrases are unique on every log:

Synchronization completed successfully
Synchronization completed with warnings
Synchronization completed with errors
Synchronization was aborted

and

Nothing to synchronize

There is a script I just found that I am reading right now from a post from the author of FFS that may explain a lot to some of you. Here is the script:

Code: Select all

Option Explicit
'--------------------------------------------------------------
'                      FreeFileSync.vbs
'--------------------------------------------------------------
' Runs FreeFileSync.exe with specified batch file.
' Sends email with status, errors, and warnings on completion.
'--------------------------------------------------------------
' Author: Lane Beneke - Southern Piping Company
'   Date: 2013.01.17
'  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>
'
'  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.
'--------------------------------------------------------------
' Copyright 2012 Lane Beneke - Southern Piping Company
'
' This program is free software: you can redistribute it and/or
' modify it under the terms of the GNU General Public License as
' published by the Free Software Foundation, either version 3 of
' the License, or (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program.  If not, see <http://www.gnu.org/licenses/>.
'--------------------------------------------------------------
'   Author: Lane Beneke - Southern Piping Company
'  Version: 2012.11.30 - Version 1.0
'Changelog: Initial release
'--------------------------------------------------------------
'   Author: Lane Beneke - Southern Piping Company
'  Version: 2012.12.05 - Version 1.1
'Changelog: Added functionality to scan log files for errors
'           and warnings, adding them to the notification
'           email message.  This included...
'            - changing email msg format to HTML
'            - finding, opening, and reading log file
'--------------------------------------------------------------
'   Author: Lane Beneke - Southern Piping Company
'  Version: 2013.01.17 - Version 1.2
'Changelog: Added HideConsole variable and associated code.
'           Added command line parser.
'--------------------------------------------------------------

'--------------------------------------------------------------
' CHANGE THE FOLLOWING VALUES AS APPROPRIATE
Const HideConsole = True
Const ExeFile = "C:\Program Files\FreeFileSync\FreeFileSync.exe"
Const BatchFile = "C:\Program Files\FreeFileSync\SyncJob.ffs_batch"
' "BatchName" IN MSGSUBJECT REPLACED WITH BATCH FILE NAME LESS PATH AND EXTENSION
Const MsgSubject = "FreeFileSync results for batch BatchName"
Const MsgFrom = "FreeFileSync@Do.Not.Reply"
Const MsgTo = "someone@yourdomain.tld"
Const SMTPServer = "mail.yourdomain.tld"
Const SMTPPort = 25
Const DoDebug = False
'--------------------------------------------------------------

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

bHideConsole = HideConsole
sExeFile = ExeFile
sBatchFile = BatchFile
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/smtpserverport") = SMTPPort
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'SendUsingPort
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(7,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) = "SMTPPort"
ArgArray(7,1) = "oMsg.Configuration.Fields.Item(""http://schemas.microsoft.com/cdo/configuration/smtpserverport"")"
Set Args = WScript.Arguments
ArgErrors = ""
For i = 0 To Args.Count - 1
   ArgFound = False
   For j = 0 To 7
      ArgTemp = ArgArray(j,0)
      ArgLen = Len(ArgTemp)
      If UCase(ArgTemp) = Left(UCase(Args.Item(i)),ArgLen) Then 'Found our argument
         ArgFound = True
         If DoDebug Then WScript.Echo "Argument " & Args.Item(i) & " matches " & ArgArray(j,0)
         If Len(Args.Item(i)) > ArgLen And Mid(Args.Item(i),ArgLen+1,1) = "=" Then
            Execute( ArgArray(j,1) & " = " & "Mid(Args.Item(i),ArgLen+2)" )
            If DoDebug Then WScript.Echo "Argument processed: " & ArgArray(j,1) & " = " & Mid(Args.Item(i),ArgLen+2)
         ElseIf Len(Args.Item(i)) = ArgLen Then
            i = i + 1
            If Args.Item(i) = "=" Then i = i + 1
            Execute( ArgArray(j,1) & " = " & "Args.Item(i)" )
            If DoDebug Then WScript.Echo "Argument processed: " & ArgArray(j,1) & " = " & Args.Item(i)
         End If
      End If
   Next
   If Not ArgFound Then ArgErrors = ArgErrors & vbCrLf & "Error: Invalid Argument: " & Args.Item(i)
Next
If ArgErrors <> "" Then
   WScript.Echo "Unable to continue due to command line errors..."
   WScript.Echo ArgErrors
   WScript.Quit
End If

'--------------------------------------------------------------
'                     BEGIN MAIN PROGRAM
'--------------------------------------------------------------
If DoDebug Then WScript.Echo "Executing program: """ & sExeFile & """ """ & sBatchFile & """"
Dim WshShell, sBatchName, iExitCode
Set WshShell = WScript.CreateObject("WScript.Shell")
dtExecutionTime = Now() 'MUST OCCUR IMMEDIATELY BEFORE PROGRAM EXECUTION
iExitCode = WshShell.Run( """" & ExeFile & """ """ & sBatchFile & """", iif(bHideConsole,0,1), True )
If DoDebug Then WScript.Echo "Program execution completed with exitcode: " & iExitCode & " " & ExitCodeArray(iExitCode)

' ADD EXIT CODE DESCRIPTION TO EMAIL MESSAGE
oMsg.HTMLBody = ExitCodeArray(iExitCode)

' IF WE DIDN'T COMPLETE SUCCESSFULLY, THEN SCAN FOR ERRORS AND WARNINGS
sLogFile = GetLogFile
If iExitCode <> 0 Then
   ' RETRIEVE LOG FILE FOLDER FROM ffs_batch FILE
   Dim objFS, objFil, sLine, DoRead
   If sLogFile = "" Then
      If DoDebug Then WScript.Echo sErrLogNotFound
      oMsg.HTMLBody = oMsg.HTMLBody & "<br><br>" & sErrLogNotFound
   ElseIf sLogFile = "None" Then
      If DoDebug Then WScript.Echo sErrLogNotCfgrd
      oMsg.HTMLBody = oMsg.HTMLBody & "<br><br>" & sErrLogNotCfgrd
   Else
      If DoDebug Then WScript.Echo "Scanning Log File"
      Set objFS = CreateObject("Scripting.FileSystemObject")
      Set objFil = objFS.OpenTextFile(sLogFile, 1) ' OPEN LOG FILE FOR READING
      DoRead = True
      Do Until objFil.AtEndOfStream
         if DoRead Then sLine = objFil.ReadLine
         DoRead = True
         If DoDebug Then WScript.Echo "Readline1 = " & sLine
         If InStr(sLine, "] Error:") > 0 _
         Or InStr(sLine, "] Warning:") > 0 Then
            oMsg.HTMLBody = oMsg.HTMLBody & "<br><br>" & sLine
            If Not objFil.AtEndOfStream Then
               sLine = objFil.ReadLine
               If DoDebug Then WScript.Echo "Readline2 = " & sLine
               Do Until objFil.AtEndOfStream Or Left(sLine,1) = "["
                  oMsg.HTMLBody = oMsg.HTMLBody & "<br>" & sLine
                  sLine = objFil.ReadLine
                  If DoDebug Then WScript.Echo "Readline3 = " & sLine
               Loop
               DoRead = False
            End If
         End If
      Loop
      objFil.Close
   End If
End If

' SEND THE EMAIL
oMsg.Subject = Replace(oMsg.Subject, "BatchName", sBatchName)
oMsg.Configuration.Fields.Update
oMsg.Send
If DoDebug Then
   WScript.Echo vbCrLf & sDashedLine
   WScript.Echo "Subject: " & oMsg.Subject
   WScript.Echo "   From: " & oMsg.From
   WScript.Echo "     To: " & oMsg.To
   WScript.Echo sDashedLine
   WScript.Echo oMsg.HTMLBody
   WScript.Echo sDashedLine
   WScript.Sleep 5000 'SLEEP 5 SECONDS FOR VIEWING BEFORE WINDOW CLOSES.
End If

'--------------------------------------------------------------
'        END MAIN PROGRAM - BEGIN FUNCTIONS AND SUBS
'--------------------------------------------------------------

Function GetLogFileName
   Dim sLogFName
   sLogFName = Mid(sBatchFile,InStrRev(sBatchFile,"\")+1)
   sLogFName = Left(sLogFName,InStrRev(sLogFName,".")-1)
   sBatchName = sLogFName
   If DoDebug Then WScript.Echo "sBatchName = " & sBatchName
   sLogFName = sLogFName & " " & Year(dtExecutionTime) & "-" & ZeroPad(Month(dtExecutionTime),2) _
      & "-" & ZeroPad(Day(dtExecutionTime),2) & " " & ZeroPad(Hour(dtExecutionTime),2) _
      & ZeroPad(Minute(dtExecutionTime),2) & ZeroPad(Second(dtExecutionTime),2) & ".log"
   GetLogFileName = sLogFName
End Function

Function GetLogFile
   Dim objFSO, objFile, sLine, x, sLogFolder, colFiles
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objFile = objFSO.OpenTextFile(sBatchFile, 1) ' OPEN BATCH FILE FOR READING

   sLine = ""
   Do Until objFile.AtEndOfStream Or sLine <> ""
      sLine = objFile.ReadLine
      If InStr( sLine, "LogfileFolder" ) Then 'FIND LINE CONTAINING LOG FILE FOLDER
         'GET DATA BETWEEN FIRST GREATER THAN SIGN AND LAST LESS THAN SIGN
         x = InStr( sLine, ">" )+1
         sLogFolder = Mid(sLine, x, InStr(x, sLine, "<" ) - x )
      Else
         sLine = ""
      End If
   Loop
   objFile.Close
   Set objFile = Nothing
   If DoDebug Then WScript.Echo "Log File Folder = " & sLogFolder

   If sLine <> "" Then
      For x = 1 To 60
         sLine = sLogFolder & "\" & GetLogFileName
         If objFSO.FileExists(sLine) Then Exit For
         'INCREMENT THE EXECUTION TIME BY ONE SECOND
         dtExecutionTime = dtExecutionTime + 1.0/86400.0
         sLine = ""
      Next
   Else
      sLine = "None"
   End If
   If DoDebug Then WScript.Echo "GetLogFile return value = " & sLine
   
   GetLogFile = sLine
End Function

Function ZeroPad( number, chars )
   Dim sReturn
   sReturn = number
   sReturn = String(chars - Len(sReturn), "0") & sReturn
   ZeroPad = sReturn
End Function

Function iif( test, trueresult, falseresult )
   If test Then
      iif = trueresult
   Else
      iif = falseresult
   End If
End Function

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: mailsend script for FreeFileSync

#33 Post by foxidrive » 15 Apr 2014 01:36

This should set the subject string in a variable and you can use %subject% in your email command.

Code: Select all

@echo off
set subject=[result undetermined]
for /f "delims=" %%x in ('dir "C:\FFS\Logs\" /od /b') do set recent=%%x
findstr  /i /c:"successfully" /c:"Nothing to synchronize" "C:\FFS\Logs\%recent%" >nul && set subject=[passed]
findstr  /i "warnings errors aborted" "C:\FFS\Logs\%recent%" >nul && set subject=[failed]


eahm
Posts: 34
Joined: 14 Apr 2014 12:49

Re: mailsend script for FreeFileSync

#34 Post by eahm » 15 Apr 2014 01:55

Thank you foxidrive.

Should this be ok as full script?

Code: Select all

@echo off
set subject=[result undetermined]
for /f "delims=" %%x in ('dir "C:\FFS\Logs\" /od /b') do set recent=%%x
findstr  /i /c:"successfully" /c:"Nothing to synchronize" "C:\FFS\Logs\%recent%" >nul && set subject=[passed]
findstr  /i "warnings errors aborted" "C:\FFS\Logs\%recent%" >nul && set subject=[failed]
if "%variable%" == "passed" (
"C:\FFS\mailsend.exe" +bc +cc -v -smtp smtp.gmail.com -ssl -port 465 -auth -from 1STEMAIL -to 1STEMAIL -cc 2NDEMAIL -user 1STEMAIL -pass PASSWORD -sub "FFS_COMPANYNAME/PCNAME-BACKUPNAME: %time%, %date% - [Passed] Synchronization completed successfully" -attach "C:\FFS\Logs\%recent%"
)
if "%variable%" == "failed" (
"C:\FFS\mailsend.exe" +bc +cc -v -smtp smtp.gmail.com -ssl -port 465 -auth -from 1STEMAIL -to 1STEMAIL -cc 2NDEMAIL -user 1STEMAIL -pass PASSWORD -sub "FFS_COMPANYNAME/PCNAME-BACKUPNAME: %time%, %date% - [Failed] Synchronization completed with errors" -attach "C:\FFS\Logs\%recent%"
)

penpen
Expert
Posts: 1999
Joined: 23 Jun 2013 06:15
Location: Germany

Re: mailsend script for FreeFileSync

#35 Post by penpen » 15 Apr 2014 02:13

I think this:
foxidrive wrote:This should set the subject string in a variable and you can use %subject% in your email command.
should be understand as, just executing something like that after foxidrive's above code:

Code: Select all

"C:\FFS\mailsend.exe" +bc +cc -v -smtp smtp.gmail.com -ssl -port 465 -auth -from 1STEMAIL -to 1STEMAIL -cc 2NDEMAIL -user 1STEMAIL -pass PASSWORD -sub "FFS_COMPANYNAME/PCNAME-BACKUPNAME: %time%, %date% - %subject%"  -attach "C:\FFS\Logs\%recent%"
No need to use different if cases.
The environment variable "subject" will contain "[result undetermined]", "[passed]", or "[failed]" and an email is send for sure (not sure if %subject% is at the right place).

penpen

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: mailsend script for FreeFileSync

#36 Post by foxidrive » 15 Apr 2014 02:51

Just to be clear, as penpen said the variable %subject% contains the string, and it changes depending on the result.
You then use the same variable in all cases, so only one mail command is needed.

I modified the strings to suit what you had in your script.

Code: Select all

@echo off
set subject=[result undetermined] The search terms were not found
for /f "delims=" %%x in ('dir "C:\FFS\Logs\" /od /b') do set recent=%%x
findstr  /i /c:"successfully" /c:"Nothing to synchronize" "C:\FFS\Logs\%recent%" >nul && set subject=[Passed] Synchronization completed successfully
findstr  /i "warnings errors aborted" "C:\FFS\Logs\%recent%" >nul && set subject=[Failed] Synchronization completed with errors

"C:\FFS\mailsend.exe" +bc +cc -v -smtp smtp.gmail.com -ssl -port 465 -auth -from 1STEMAIL -to 1STEMAIL -cc 2NDEMAIL -user 1STEMAIL -pass PASSWORD -sub "FFS_COMPANYNAME/PCNAME-BACKUPNAME: %time%, %date% - %subject%" -attach "C:\FFS\Logs\%recent%"

Squashman
Expert
Posts: 4472
Joined: 23 Dec 2011 13:59

Re: mailsend script for FreeFileSync

#37 Post by Squashman » 15 Apr 2014 06:38

eahm wrote:Thank you foxidrive.

Should this be ok as full script?

No. He is not using %variable% as the variable holding the string. He changed it to %subject%

Squashman
Expert
Posts: 4472
Joined: 23 Dec 2011 13:59

Re: mailsend script for FreeFileSync

#38 Post by Squashman » 15 Apr 2014 06:44

eahm wrote:They are two different kind of batch files, one must be launched from FreeFileSync called batch file but is an xml file with all the configurations inside, its extension is .ffs_batch.

The other batch file, launched when .ffs_batch is done with the backup run, is the .bat I need to get to work. It's made ONLY for mailsend.exe, ONLY to try to read and send the logs via email when the backup run is done and when .ffs_batch calls it.

You may want to make things much more clear when you use the word BATCH on this forum. When you say BATCH most of us will assume you me you are running a .BAT file.

eahm wrote:Apologize if this wasn't clear from the beginning, I assumed you all know FreeFileSync.

Yes. That is a very misinformed statement.

From looking at the VBS you posted it does look like it is possible to capture the errorlevels out of FreeFileSync. Not sure why you just didn't use the VBS. That way you don't need a 3rd party utility to send the email. The VBS handles doing everything. One script and your done.

eahm
Posts: 34
Joined: 14 Apr 2014 12:49

Re: mailsend script for FreeFileSync

#39 Post by eahm » 15 Apr 2014 09:08

Squashman wrote:From looking at the VBS you posted it does look like it is possible to capture the errorlevels out of FreeFileSync. Not sure why you just didn't use the VBS. That way you don't need a 3rd party utility to send the email. The VBS handles doing everything. One script and your done.

I am trying to, I just found that file.

I can't let it connect to Gmail, I found almost all the strings but I am still missing the authentication one, I will find it.
Also, it doesn't attach the log file, the script we're trying to make here works much better.

Code: Select all

Const MsgSubject = "FreeFileSync results for batch BatchName"
Const MsgFrom = "FreeFileSync@Do.Not.Reply"
Const MsgTo = "someone@yourdomain.tld"
Const SMTPServer = "mail.yourdomain.tld"
Const SMTPPort = 25
Const DoDebug = False
Const SMTPLogon = "mail.yourdomain.tld"
Const SMTPPassword = "password"
Const SMTPSSL = True
Const SMTPPort = 465
AUTH???


Code: Select all

@echo off
set subject=[Failed] The search terms were not found
for /f "delims=" %%x in ('dir "C:\FFS\Logs\" /od /b') do set recent=%%x
findstr  /i /c:"successfully" /c:"Nothing to synchronize" "C:\FFS\Logs\%recent%" >nul && set subject=[Success] Synchronization completed successfully
findstr  /i "warnings errors aborted" "C:\FFS\Logs\%recent%" >nul && set subject=[Failed] Synchronization completed with errors

"C:\FFS\mailsend.exe" +bc +cc -v -smtp smtp.gmail.com -ssl -port 465 -auth -from EMAIL -to EMAIL -cc EMAIL -bc EMAIL -user EMAIL -pass PASSWORD -sub "FFS_COMPANYNAME/SOURCE-FOLDER_DESTINATION-FOLDER_WHEN: %time%, %date% - %subject%" -attach "C:\FFS\Logs\%recent%"

foxidrive, thank you so much, this one is perfect.


Thank you everyone for the replies.

Do you guy think it's easier to let it look inside the logs instead of checking the return code then send the email? I have no idea how many terms may be inside the log file but with return codes I know for sure there are four.

edit:
Changed "[Result undetermined] The search terms were not found" to "[Failed] The search terms were not found". If nothing is found it means there is something wrong so, [Failed].

eahm
Posts: 34
Joined: 14 Apr 2014 12:49

Re: mailsend script for FreeFileSync

#40 Post by eahm » 14 Feb 2015 00:44

Guys, I have no idea why I didn't notice this earlier but when there is nothing to synchronize I receive the message "[Failed] The search terms were not found".

I am currently using this code:

Code: Select all

@echo off
set subject=[Failed] The search terms were not found
for /f "delims=" %%x in ('dir "C:\FFS\Logs\" /od /b') do set recent=%%x
findstr  /i /c:"successfully" /c:"Nothing to synchronize" "C:\FFS\Logs\%recent%" >nul && set subject=[Success] Synchronization completed successfully
findstr  /i "warnings errors aborted" "C:\FFS\Logs\%recent%" >nul && set subject=[Failed] Synchronization completed with errors

"C:\FFS\mailsend.exe" +bc +cc -v -smtp smtp.gmail.com -ssl -port 465 -auth -from EMAIL -to EMAIL -cc EMAIL -bc EMAIL -user EMAIL -pass PASSWORD -sub "FFS_COMPANYNAME/SOURCE-FOLDER_DESTINATION-FOLDER_WHEN: %time%, %date% - %subject%" -attach "C:\FFS\Logs\%recent%"

What am I missing???

edit:

I am getting: "FINDSTR: Cannot open C:\FFS\Logs\[Data01]_[BAK2TBioS]-BAK_24Hours 2015-02-13 23˸56˸10.log"

edit2:

I tried to insert "timeout /t 5" and nothing, same error, cannot open the .log, I thought maybe the files was locked by the backup software for few seconds after the backup completed.

edit3:

Final code, this should work but it can't open the .log file still:

Code: Select all

@echo off
timeout /t 5
set subject=[Failed] The search terms were not found
for /f "delims=" %%x in ('dir "C:\FFS\Logs\" /od /b') do set recent=%%x
findstr /i "successfully" "C:\FFS\Logs\%recent%" >nul && set subject=[Success] Synchronization completed successfully
findstr /i /c:"Nothing to synchronize" "C:\FFS\Logs\%recent%" >nul && set subject=[Success] Nothing to synchronize
findstr /i "warnings errors aborted" "C:\FFS\Logs\%recent%" >nul && set subject=[Failed] Synchronization completed with errors

"C:\FFS\mailsend.exe" +cc +bc -v -smtp smtp.gmail.com -ssl -port 465 -auth -user EMAIL -pass PASSWORD -f EMAIL -to EMAIL -cc EMAIL -bc EMAIL -sub "FFS_COMPANYNAME/SOURCE-FOLDER_DESTINATION-FOLDER_WHEN: %time%, %date% - %subject%" -attach "C:\FFS\Logs\%recent%"

The log file doesn't open ONLY WHEN Nothing to synchronize is present.
Last edited by eahm on 14 Feb 2015 01:29, edited 1 time in total.

eahm
Posts: 34
Joined: 14 Apr 2014 12:49

Re: mailsend script for FreeFileSync

#41 Post by eahm » 14 Feb 2015 01:26

I am opening another post for another feature request.

How can I completely remove/ignore the "C:\FFS\Logs" folder and tell findstr to look ONLY in "C:\FFS\LastSync.log" then send emails accordingly?

The file LastSync.log is created instantaneously after a backup and replaced every time.

I am afraid something changed after an update and findstr can't open that file name anymore? LastSync.log is simple and should never be an issue.

Thank you.
Last edited by eahm on 14 Feb 2015 01:32, edited 1 time in total.

ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: mailsend script for FreeFileSync

#42 Post by ShadowThief » 14 Feb 2015 01:32

Delete the line

Code: Select all

for /f "delims=" %%x in ('dir "C:\FFS\Logs\" /od /b') do set recent=%%x


Change every instance of "C:\FFS\Logs\%recent%" to "C:\FFS\LastSync.log"

eahm
Posts: 34
Joined: 14 Apr 2014 12:49

Re: mailsend script for FreeFileSync

#43 Post by eahm » 14 Feb 2015 01:53

ShadowThief, thank you. I am sure the new script works perfectly but why am I still getting this: "FINDSTR: Cannot open C:\FFS\LastSync.log"?

New script, just for verification:

Code: Select all

@echo off
timeout /t 5
set subject=[Failed] The search terms were not found
findstr /i "successfully" "C:\FFS\LastSync.log" >nul && set subject=[Success] Synchronization completed successfully
findstr /i /c:"nothing to synchronize" "C:\FFS\LastSync.log" >nul && set subject=[Success] Nothing to synchronize
findstr /i "warnings errors aborted" "C:\FFS\LastSync.log" >nul && set subject=[Failed] Synchronization completed with errors

"C:\FFS\mailsend.exe" +cc +bc -v -smtp smtp.gmail.com -ssl -port 465 -auth -user EMAIL -pass PASSWORD -f EMAIL -to EMAIL -cc EMAIL -bc EMAIL -sub "FFS_COMPANYNAME/SOURCE-FOLDER_DESTINATION-FOLDER_WHEN: %time%, %date% - %subject%" -attach "C:\FFS\LastSync.log"


edit:

Just tried on three different computers and on mine as well, changed the folder with a test .log file and cmd opened with admin rights. Nothing. Still "FINDSTR: Cannot open d:\ffs\lastsync.log". I have no idea why.

ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: mailsend script for FreeFileSync

#44 Post by ShadowThief » 14 Feb 2015 02:25

You generally get that error message when the file does not exist.

eahm
Posts: 34
Joined: 14 Apr 2014 12:49

Re: mailsend script for FreeFileSync

#45 Post by eahm » 14 Feb 2015 10:54

ShadowThief, yes. An s was missing from the last script (LastSyncs.log, sorry 1:30am I was too tired but the previous script stopped working after the latest ~1GB Microsoft update.

edit:
And, this new script is NOT going to work properly, the file LastSyncs.log is not being replaced every time but it's being updated with the latest backup log report. All the searches will be there after few days.

edit2:
Is there a way to tell delims to look ONLY in the first line of LastSyncs.log? That way will work.

edit3:
I don't understand why would this code stop working? Is there anything I have to change?

Code: Select all

@echo off
timeout /t 5
set subject=[Failed] The search terms were not found
for /f "delims=" %%x in ('dir "C:\FFS\Logs\" /od /b') do set recent=%%x
findstr /i "successfully" "C:\FFS\Logs\%recent%" >nul && set subject=[Success] Synchronization completed successfully
findstr /i /c:"Nothing to synchronize" "C:\FFS\Logs\%recent%" >nul && set subject=[Success] Nothing to synchronize
findstr /i "warnings errors aborted" "C:\FFS\Logs\%recent%" >nul && set subject=[Failed] Synchronization completed with errors

"C:\FFS\mailsend.exe" +cc +bc -v -smtp smtp.gmail.com -ssl -port 465 -auth -user EMAIL -pass PASSWORD -f EMAIL -to EMAIL -cc EMAIL -bc EMAIL -sub "FFS_COMPANYNAME/SOURCE-FOLDER_DESTINATION-FOLDER_WHEN: %time%, %date% - %subject%" -attach "C:\FFS\Logs\%recent%"


edit4:
It worked with a modified log file without the ":". For example: [Data1]-Utils_[iTM64GBPat]-Utils 2015-02-14 124658.log

edit5:
You know something else I've updated the past week or two? FreeFileSync. Damn it, let's test the older vesion. It seems 6.14 creates the ":" in a different coding. Testing 6.13.
Damn it again, from the changelog: "Use colon as time stamp seperator in log file names"
Last edited by eahm on 14 Feb 2015 14:44, edited 3 times in total.

Post Reply