Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
eahm
- Posts: 34
- Joined: 14 Apr 2014 12:49
#61
Post
by eahm » 19 Feb 2015 12:23
I will try this one ASAP:
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
#63
Post
by eahm » 19 Feb 2015 12:42
I am really confused. I kind of understand now that the script stops at the first character of the second line and it's the date? Is there a way to fix that, sorry if you already posted it.
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#64
Post
by Squashman » 19 Feb 2015 13:00
The variable %first_line% is equal to this:
Code: Select all
| 2/19/2015 - [Data1]-Utils_[iTM64GBPat]-Utils: Synchronization completed successfully
It starts with a
|.
You can't echo a pipe without quoting it.
Which is why I gave you these two examples.
One works and the other does not.
Code: Select all
echo | 2/19/2015 - [Data1]-Utils_[iTM64GBPat]-Utils: Synchronization completed successfully | findstr /i "successfully nothing"
echo " | 2/19/2015 - [Data1]-Utils_[iTM64GBPat]-Utils: Synchronization completed successfully" | findstr /i "successfully nothing"
Do you see the difference?
-
eahm
- Posts: 34
- Joined: 14 Apr 2014 12:49
#65
Post
by eahm » 19 Feb 2015 13:09
I see quotes and two spaces but I can't just damn program to save my life, let's try this. Should I replace
with
Are the spaces necessary?
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#66
Post
by Squashman » 19 Feb 2015 13:15
eahm wrote:I see quotes and two spaces but I can't just damn program to save my life, let's try this. Should I replace
with
Are the spaces necessary?
No spaces necessary. Just quote the variable.
The only reason I had the spaces was because the first line actually does have leading spaces according to the output you posted.
Your output has two spaces and a PIPE.
Code: Select all
echo | 2/19/2015 - [Data1]-Utils_[iTM64GBPat]-Utils: Synchronization completed successfully
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#67
Post
by foxidrive » 19 Feb 2015 13:25
eahm wrote:Are the spaces necessary?
Just clarifying here - no
extra spaces are necessary.
eahm wrote:Sorry I only edit when I say things not relevant to what we are doing
If ten people read your post about 15 minutes after you create it - and you edit it 3 times in the next 4 hours,
none of those people will know that you have changed your post at all.
I think that most of us here would use the "read new posts" feature of the forum and so wouldn't see your changes.
It looks like you removed the information about the input file too.
-
eahm
- Posts: 34
- Joined: 14 Apr 2014 12:49
#68
Post
by eahm » 19 Feb 2015 13:31
This is beautiful, both scripts working perfectly:
mailsend.bat (Logs folder):
Code: Select all
@echo off
timeout /t 3
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%"
mailsend.bat (LastSyncs.log):
Code: Select all
@echo off
timeout /t 3
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"
Can I send some money?
edit:
No question here, foxidrive, ShadowThief and Squashman please PM your PayPal.
Last edited by
eahm on 19 Feb 2015 13:38, edited 1 time in total.
-
eahm
- Posts: 34
- Joined: 14 Apr 2014 12:49
#70
Post
by eahm » 19 Feb 2015 13:43
foxidrive wrote:Read the post above yours.
You're right sorry, I replied too many times too fast. Please consider adding 1 hour time limit for editing in the forum?
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#71
Post
by Squashman » 19 Feb 2015 14:27
eahm wrote:You're right sorry, I replied too many times too fast. Please consider adding 1 hour time limit for editing in the forum?
We have already discussed that and decided against it. Mostly because people like dbenham post a lot of code that is really big. Every time he comes out with a new version he replaces the code in the first post but then also posts another comment saying he updated the code in the first post. That way we don't have 600 lines of code a dozen times in the thread and nobody knows which version to copy.
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#72
Post
by Squashman » 19 Feb 2015 14:30
eahm wrote:No question here, foxidrive, ShadowThief and Squashman please PM your PayPal.
We don't come here to get paid. We come here for the knowledge and hopefully we are teaching others at the same time.
-
eahm
- Posts: 34
- Joined: 14 Apr 2014 12:49
#73
Post
by eahm » 19 Feb 2015 14:58
Squashman wrote:We don't come here to get paid. We come here for the knowledge and hopefully we are teaching others at the same time.
I do that to, always did BUT if I knew you and saw you at the bar I would have paid you a beer, this would be the same

Your call guys, thanks again.