mailsend script for FreeFileSync

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: mailsend script for FreeFileSync

#46 Post by ShadowThief » 14 Feb 2015 13:28

You can extract the first line of a file to a variable like this:

Code: Select all

set /p first_line=<"C:\FFS\LastSyncs.log"


And from there, you can just search through that string.

Code: Select all

echo %first_line%|findstr /i "successfully" >nul && set subject=[Success] Synchronization completed successfully

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

Re: mailsend script for FreeFileSync

#47 Post by eahm » 14 Feb 2015 14:58

This one still works perfectly, I made few changes earlier (/c: etc.) and modified others now (one line for successfully and nothing) again:

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 "successfully nothing" "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" +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%"


Also I've contacted the developer about the colons (:).

edit:
Thank you ShadowThief, I am trying to switch to LastSyncs.log. Do I keep the two lined after @echo? Sorry I am still at the point where I need to see all written down in a code.
Last edited by eahm on 17 Feb 2015 13:16, edited 3 times in total.

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

Re: mailsend script for FreeFileSync

#48 Post by ShadowThief » 14 Feb 2015 16:17

Ah, sorry...

Code: Select all

@echo off
timeout /t 5
set subject=[Failed] The search terms were not found

set /p first_line=<"C:\FFS\LastSyncs.log"
echo %first_line%|findstr /i "successfully" >nul && set subject=[Success] Synchronization completed successfully
echo %first_line%|findstr /i /c:"Nothing to synchronize" >nul && set subject=[Success] Nothing to synchronize
echo %first_line%|findstr /i "warnings errors aborted" >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\LastSyncs.log"

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

Re: mailsend script for FreeFileSync

#49 Post by eahm » 14 Feb 2015 16:38

Sorry it's the second line not the first. Is there a way to make it work with that? Thanks.

Code: Select all

_____________________________________________________________________
|2/14/2015 - [Data1]-Utils_[iTM64GBPat]-Utils: Nothing to synchronize

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

Re: mailsend script for FreeFileSync

#50 Post by eahm » 18 Feb 2015 21:00

eahm wrote:Sorry it's the second line not the first. Is there a way to make it work with that? Thanks.

Code: Select all

_____________________________________________________________________
|2/14/2015 - [Data1]-Utils_[iTM64GBPat]-Utils: Nothing to synchronize

Anyone guys? Thanks again.
Last edited by eahm on 18 Feb 2015 22:34, edited 2 times in total.

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

Re: mailsend script for FreeFileSync

#51 Post by ShadowThief » 18 Feb 2015 21:52

Replace the set /p first_line line with

Code: Select all

(
set /p ignore=
set /p first_line=
)<"C:\FFS\LastSyncs.log"



EDIT: And now that I'm not posting from my phone...

Code: Select all

@echo off
timeout /t 5
set subject=[Failed] The search terms were not found

(
    set /p ignore=
    set /p first_line=
)<"C:\FFS\LastSyncs.log"
echo %first_line%|findstr /i "successfully" >nul && set subject=[Success] Synchronization completed successfully
echo %first_line%|findstr /i /c:"Nothing to synchronize" >nul && set subject=[Success] Nothing to synchronize
echo %first_line%|findstr /i "warnings errors aborted" >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\LastSyncs.log"

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

Re: mailsend script for FreeFileSync

#52 Post by eahm » 19 Feb 2015 08:57

Something is not working, even if I add pause at the end I don't see the bat starting at all.

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

Re: mailsend script for FreeFileSync

#53 Post by Squashman » 19 Feb 2015 09:30

eahm wrote:Something is not working, even if I add pause at the end I don't see the bat starting at all.

Troubleshoot it!

Turn ECHO ON in the batch file.
Run the batch file from the cmd prompt instead of double clicking it.

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

Re: mailsend script for FreeFileSync

#54 Post by eahm » 19 Feb 2015 09:40

Code: Select all

C:\FFS>(
set /p ignore=
 set /p first_line=
) 0<"C:\FFS\LastSyncs.log"

C:\FFS>echo   | 2/19/2015 - [Data1]-Utils_[iTM64GBPat]-Utils: Synchronization co
mpleted successfully  | findstr /i "successfully nothing"   1>nul  && set subjec
t=[Success] Synchronization completed successfully
'2' is not recognized as an internal or external command,
operable program or batch file.

C:\FFS>
Last edited by eahm on 19 Feb 2015 10:29, edited 1 time in total.

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

Re: mailsend script for FreeFileSync

#55 Post by foxidrive » 19 Feb 2015 09:53

eahm wrote:

Code: Select all

C:\FFS>(
set /p ignore=
 set /p first_line=
) 0<"C:\FFS\LastSyncs.log"

C:\FFS>echo   | 2/19/2015 - [Data1]-Utils_[iTM64GBPat]-Utils: Synchronization co
mpleted successfully  | findstr /i "successfully nothing"   1>nul  && set subjec
t=[Success] Synchronization completed successfully
'2' is not recognized as an internal or external command,
operable program or batch file.

C:\FFS>



I see that you changed the code from what ShadowThief has in his post - are you sure that your edit, or a mistake while editing, hasn't made it stop working?

I haven't tested any code here - and I don't have your input file to test with - I'm just saying that the code is different.

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

Re: mailsend script for FreeFileSync

#56 Post by eahm » 19 Feb 2015 09:54

I am sure I already did but I will try again with his exact version.

Exact version:

Code: Select all

C:\FFS>mailalert.bat
'2' is not recognized as an internal or external command,
operable program or batch file.

C:\FFS>

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

Re: mailsend script for FreeFileSync

#57 Post by Squashman » 19 Feb 2015 10:41

:D

Code: Select all

H:\>echo   | 2/19/2015 - [Data1]-Utils_[iTM64GBPat]-Utils: Synchronization completed successfully  | findstr /i "successfully nothing"
'2' is not recognized as an internal or external command,
operable program or batch file.

H:\>echo  " | 2/19/2015 - [Data1]-Utils_[iTM64GBPat]-Utils: Synchronization completed successfully"  | findstr /i "successfully nothing"
 " | 2/19/2015 - [Data1]-Utils_[iTM64GBPat]-Utils: Synchronization completed successfully"

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

Re: mailsend script for FreeFileSync

#58 Post by foxidrive » 19 Feb 2015 11:56

eahm wrote:I am sure I already did but I will try again with his exact version.

Exact version:

Code: Select all

C:\FFS>mailalert.bat
'2' is not recognized as an internal or external command,
operable program or batch file.

C:\FFS>


Yes, the data you provided has a pipe at the start which is hard to see.
Squashman has the answer to that.

I looked at the recent posts in this thread and it looks like you keep editing your posts - do you do that a long time after posting? People will not see the edits if you do that.

Did you remove the data about the input file too?

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

Re: mailsend script for FreeFileSync

#59 Post by eahm » 19 Feb 2015 12:15

Sorry I only edit when I say things not relevant to what we are doing and because English is my 3rd language (edit here once).

I have no idea what Squashman did with that reply...

Last test I did was with the version ShadowThief posted and LastSyncs.log already present in the folder.

I can try again and double check every single step?

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

Re: mailsend script for FreeFileSync

#60 Post by Squashman » 19 Feb 2015 12:20

eahm wrote:I have no idea what Squashman did with that reply...

Well Foxidrive pointed out what character is causing the problem and I showed you the result of your existing code and what happens when you fix the code.
You should see the difference within the first 6 characters of the code.

Post Reply