Solved How can I find a string in log file at current hour minute ?

Mobile computing solutions Mini itx pfse...
November 18, 2015 at 12:30:42
Specs: Windows XP, HexaCore AMD FX-6100, 1400 MHz (7 x 200) / 4gb DDR
Can someone please help ?

I wrote a batch file to search my log file but I keep finding the same entries for the day from earlier, When I only want to find the most recent new entry to add to my counter I will put an example below.

Lines that begin as follows all have a time and date in the start of the log entries such as: (000049) 18/11/2015 18:05:00 - (not logged in)

I have omitted the contents after (not logged in) to make it simple to focus on the section for the first string which is the DATE and TIME after the index number which is to be ignored.

I can use a %VAR$ for searching the %date% %time% but the line must also contain my 2nd %STRING% which is: RETR ortnew.txt

My problem is the current search algorithm I am using keeps returning previous results and adding them to my counter over and over again when I only want to do a count for the number of downloads for that particular file for today once. Lets say their was 6 downloads for RETR ortnew.txt in the DAILY log file as a new log file is created each day then I want to be able to count those only once store in either a text file or variable and not cout them twice but each time their is a change in the logfile size my search runs again to check for newly downloaded file.

CURRENT SEARCH IS BASICALLY THIS:

>nul find "RETR ortnew" %filezilllog% && (

echo We found DOWNLOADS for ortnew Today.
set filename=Counter-for-ortnew
call :counter

) || (

echo We have NOT found any DOWNLOADS for ortnew today.

)


Any help would be greatly appreciated thanks.

Michelle xoxoxox

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb

message edited by Ortorea


See More: How can I find a string in log file at current hour minute ?

Report •


✔ Best Answer
November 19, 2015 at 19:51:45
Email is fine, I got your mail! :-) Just don't check it as often as I should. (I'm officially "old people"). My batch code reached a "destructive interference" cyclical feedback. Here is this which I hope will work:

@echo off & setlocal enabledelayedexpansion
set base=ortnew
set filezillog=filezillog

(for /f "tokens=1-4" %%a in (%base%.x) do (
set k=%%a
set ld=%%~c
set lt=%%~d
)) 2>nul

for /f "tokens=1 delims=[]" %%a in ('find "retr %base%.txt"^<%filezillog%^|find /n /v ""') do set ttl=%%a

echo counted total: %ttl%
>%base%.x echo %ttl% %date% %time%
set /a dif=ttl-k
echo diff: %dif% since last checked: %ld% %lt%
::========= end
test it independent of your script - it shouldwork, as it did on my end. I added instances of "retr ortnew.txt" to filezillog and it managed to accumulate them into count.



#1
November 18, 2015 at 19:49:23
Hello O :)
I would do this. count the instances of the target-string in the logfile and record them to a "scratch" file. The scratch-file could be one for each target, or a single file with target filenames included.
The format I've used in this example: COUNT DATE1 DATE2 TIME
Four elements (since date usually has day-of-week with space between).
::--- sample batchfile logfile counter
@echo off & setlocal enabledelayedexpansion
set k=0
set base=ortnew
:: scratchfile is BASE.x
(for /f "tokens=1-4" %%a in (%base%.x) do (
set k=%%a
set ld=%%~c
set lt=%%~d
)) 2>nul

for /f "tokens=1 delims=[]" %%a in ('find "retr %lee"^<%filezillog%^|find /n /v ""') do set ttl=%%a

echo counted total: %ttl%
>%base%.x echo %ttl% %date% %time%
set /a dif=ttl-k
echo diff: %dif% since last checked: %ld% %lt%
::===== end batch


Report •

#2
November 18, 2015 at 20:29:49
Hello old friend, thanks for coming to the rescue it's been long time hope you well ? My batch has been out of order for a while as been doing other things then realized I'd broken it now it's running again will try your code thanks. It is an old problem that needed fixing was clueless as to how.

Michelle

I have put the scratch code at the bottom and am calling it from my script, so far bit quit on me so am doing a debug added some voice notifications to alert me as it can run on a loop for hours before I get a positive.

:: ************ SCRATCH FILE TO BE CALLED ****************
:scrat
set k=0
set base=ortnew
:: scratchfile is BASE.x
(for /f "tokens=1-4" %%a in (%base%.x) do (
set k=%%a
set ld=%%~c
set lt=%%~d
)) 2>nul

for /f "tokens=1 delims=[]" %%a in ('find "retr %lee"^<%filezillog%^|find /n /v

""') do set ttl=%%a

echo counted total: %ttl%
SayStatic %filename% counted total: %ttl%

>%base%.x echo %ttl% %date% %time%
set /a dif=ttl-k
echo diff: %dif% since last checked: %ld% %lt%
SayStatic %filename% Download diff: %dif% since last checked: %ld% %lt%
goto :end
:: ************ SCRATCH FILE TO BE CALLED ****************

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb

message edited by Ortorea


Report •

#3
November 19, 2015 at 14:30:00
Hi Again nbrane,
I added the code you wrote to a called section in my existing batch but so far can't get it working it keeps erroring out on: ">"

> was unexpected at this time.

Without quotes, not sure why, any idea ?

Maybe I should include the entire batch file below.

:: SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

@echo on
setlocal enabledelayedexpansion
goto nodebug
:: ********** ERROR LOGGING ********************

echo ERROR TEST LOG FLAG
IF NOT %1!==/go! %0 /go 1>C:\State\%~n0.log 2>&1
SHIFT

ECHO %1 %2 %3 %4 %5

:: ********** ERROR LOGGING ********************
:nodebug
set ftplog="C:\state\ftpgets.log"
set filename=0
set noekho=0
set Today=0
set offset=0
goto logsize
:readlog
echo READLOG
cls
:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:: START FILEZILLA LOG SNOOPING LOOKING FOR ACTIVITY
:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
call :getdate
:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
set message=Number of Downloads so Far for:
:: ---------------------------------------------------
if exist \\%computername%\filezilla-Logs\*.log set filezilllog="\\%computername%\filezilla-Logs\fzs-%YEAR%-%Month%-%Day%.log"
:: ---------------------------------------------------------
if exist %filezilllog% (goto checkm1) else (goto donelog)
:checkm1
echo ========================================================================

>nul find "RETR autoclean" %filezilllog% && (

echo We found DOWNLOADS for RETREIVE auto clean.bat Today.
SayStatic We found DOWNLOADS for RETREIVE autoclean DOT bat Today.
set filename=Counter-for-autoclean
call :counter
call :scrat

) || (

echo We have NOT found any DOWNLOADS for Auto clean.bat today.
SayStatic We have NOT found any DOWNLOADS for Auto clean DOT bat today.

)

echo ========================================================================

:logdn3

:: #########################################################

if exist %filezilllog% (goto checkm) else (goto donelog)

:checkm

>nul find "RETR Clean6" %filezilllog% && (

echo We found DOWNLOADS for RETREIVE Clean6.bat Today.
SayStatic We found DOWNLOADS for RETREIVE Clean6.bat Today.
set filename=Counter-for-Clean6
call :counter
call :scrat

) || (
echo We have NOT found any DOWNLOADS for Clean6.bat today.
SayStatic We have NOT found any DOWNLOADS for Clean6.bat today.

)

echo ========================================================================
:donelog

:: if not "%filename%"=="0" notepad %filezilllog%
echo ========================================================================
:: ###### RESETTING BEFORE TO NEW OLD VALUE TO LOOK FOR CHANGES #####
for %%a in (%filezilllog%) do (set before1=%%~za)
set before=%before1%
set offs=false
:: ##################################################################
:: END FILEZILLA LOG SNOOPING LOOKING FOR ACTIVITY
:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
set filename=0
goto end
pathping 127.0.0.1 -n -q 1 -p 20000 >nul 2>&1
:logsize
:: ################################################
:ftpsnoop
:: ########### MONITORING MY WEBSITE STATUS ###########
:: ----------------------------------------------------
ping -n 1 ftp.book-stores.com > nul
goto %errorlevel%

:0
cls
echo WEBSITE BOOK STORES IS UP!
if "%down%"=="true" SAYSTATIC BOOK STORES WEBSITE IS BACK ONLINE
if "%down%"=="true" echo BOOK STORES WEBSITE IS BACK ONLINE
set down=false
goto :cycle

:1
cls
echo WEBSITE BOOK STORES IS DOWN
if "%down%"=="false" SAYSTATIC BOOK STORES WEBSITE HAS GONE OFFLINE
if "%down%"=="false" echo BOOK STORES WEBSITE HAS GONE OFFLINE
set down=true

:cycle
:: ########### MONITORING MY WEBSITE STATUS ###########
:: ----------------------------------------------------
if "%Today%" lss "%Day%" set Today=%Day%
if exist echo del echo
echo.
echo LOG FILE FTP SNOOP

call :getdate
if exist \\%computername%\filezilla-Logs\*.log set filezilllog="\\%computername%\filezilla-Logs\fzs-%YEAR%-%Month%-%Day%.log"
:: ------------------------------------------------
if "%nolog%"=="0" if not %Day%==%Today% set before=0 && set before1=0 && set offset=0
if "%nolog%"=="0" if not %Day%==%Today% set Today=%Day%
:: ================================================
:: At the turn of the Midnight Hour Briefly The NEW Day log does not exist
:: So I need 2 passes to give FileZilla chance to Creat a new log.
if "%nolog%"=="1" if not exist %filezilllog% goto noftpsnoop
if not exist %filezilllog% (set nolog=1) else (set nolog=0)
if "%nolog%"=="1" pathping 127.0.0.1 -n -q 1 -p 120000 >nul 2>&1
:: ================================================
if not exist %filezilllog% goto noftpsnoop
if "%before1%" lss "0" for %%a in (%filezilllog%) do ( set before1=%%~za)
set /a offset=%before1%+1000
if "%before%" lss "0" set before=%before1%
for %%a in (%filezilllog%) do (if %%~za gtr %offset% set offs=true)
:: ================================================

:: ------------------------------------------------
if "A%offs%"=="Atrue" set /a before1=%offset%-1000
:: ================================================
echo.
:: ------------------------------------------------
if "%offs%"=="true" echo NEW FTP ACTIVITY ON SERVER && SayStatic FTP Server Downloads ARE In Progress.
:: ------------------------------------------------
:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo.
echo "%date%" - Filezilla LOG FILE Offset: - Value is %offset% in Bytes
echo ========================================================================
echo.
echo %time% - Filezilla LOG FILE SIZE IS: "%before1%" Any Variation in Bytes "?"
echo ========================================================================
echo.
echo %time% - Filezilla LOG FILE SIZE IS: "%before%" ALERT TRUE Value in Bytes
echo ========================================================================
echo.
if "%offs%"=="true" call poll\polling
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for /f "tokens=1 delims=:" %%a in ('findstr /n /r "^([0-9][0-9][0-9][0-9][0-9][0-9])" %filezilllog%') do set k=%%a
set /a k-=1
echo Downloads total %k%
more +%k% C:\State\ortlast.log|find "RETR">C:\State\ortlast.log
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:: ================================================
if "%offs%"=="true" call :readlog
:: ------------------------------------------------
pathping 127.0.0.1 -n -q 1 -p 30000 >nul 2>&1
cls
if not exist ftpkill goto :ftpsnoop
:noftpsnoop
if "%hickup%" lss "1" pathping 127.0.0.1 -n -q 1 -p 480000 >nul 2>&1
if "%hickup%" lss "1" set hickup=1 && goto :ftpsnoop
echo ========================================================================
echo.
echo FINISHING NO LOGS TO MONITOR
pathping 127.0.0.1 -n -q 1 -p 8000 >nul 2>&1
SayStatic Their are NO MORE FTP Server Downloads to Monitor Exiting.
echo.
echo ========================================================================
cls
:completed
endlocal
goto end
:: ------------------------------------------------

:getdate
:: ---------------------- FINDING DATE -----------------------

@For /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do @(
Set Day=%%A
Set Month=%%B
Set Year=%%C
)

goto end
:: ************ SCRATCH FILE TO BE CALLED ****************
:scrat
if not exist C:\state\base >C:\state\base echo 0
set k=0
set base=ortnew
:: scratchfile is BASE.x
(for /f "tokens=1-4" %%a in (%base%.x) do (
set k=%%a
set ld=%%~c
set lt=%%~d
)) 2>nul

for /f "tokens=1 delims=[]" %%a in ('find "retr %lee"^<%filezillog%^|find /n /v ""') do set ttl=%%a

echo counted total: %ttl%
SayStatic %filename% counted total: %ttl%

>%base%.x echo %ttl% %date% %time%
set /a dif=ttl-k
echo diff: %dif% since last checked: %ld% %lt%
SayStatic %filename% Download diff: %dif% since last checked: %ld% %lt%
goto :end
:: ************ SCRATCH FILE TO BE CALLED ****************
:counter
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:: ##### THIS COUNTER COUNTS THE NUMBER OF DOWNLOAD'S ####
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if not exist %filename%.log > %filename%.log echo 0
set /p var1=< %filename%.log
set /a var2=%var1%+1
> %filename%.log echo %var2%
echo Number of Downloads so Far for %filename% is %var2%
>> %ftplog% echo %message% %filename% is %var2%. Time:%time% Date:%date%
SayStatic The Number of Downloads so Far for %filename% is %var2%
pathping 127.0.0.1 -n -q 1 -p 5000 >nul 2>&1
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:end

:: EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb

message edited by Ortorea


Report •

Related Solutions

#4
November 19, 2015 at 17:12:18
an obvious mistake in my code:
for /f "tokens=1 delims=[]" %%a in ('find "retr %lee"^<%filezillog%^|find /n /v ""') do set ttl=%%a

I forgot to put the second percent on var "lee". That would be the first place to look. My most abject and humble apologies!
This var is also misnamed. In my script it should have been: %base%.txt (where "base" was previously assigned the value "ortnew"). SO, take out %lee and replace with %base%.txt, and see if that fixes anything.
As for testing, maybe try a "dummy" file instead of waiting for live material.
Good luck my long-time friend and mentor!


Report •

#5
November 19, 2015 at 17:38:50
Thanks Nbrane
Got it on test now we'll see how it does, :o)

OK Just ran it in the console window at least it did not quit prematurely but this error came up ...

| was unexpected at this time.
counted total:
diff: 0 since last checked:


It might be my fault had it search for: retr %base%.txt
but it only needs to find: ortnew
stored in the VAR retr %base%

Testing again

Nope this error on the | was unexpected at this time.

Michelle

PS I think maybe your old email is not working ?

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb

message edited by Ortorea


Report •

#6
November 19, 2015 at 19:51:45
✔ Best Answer
Email is fine, I got your mail! :-) Just don't check it as often as I should. (I'm officially "old people"). My batch code reached a "destructive interference" cyclical feedback. Here is this which I hope will work:

@echo off & setlocal enabledelayedexpansion
set base=ortnew
set filezillog=filezillog

(for /f "tokens=1-4" %%a in (%base%.x) do (
set k=%%a
set ld=%%~c
set lt=%%~d
)) 2>nul

for /f "tokens=1 delims=[]" %%a in ('find "retr %base%.txt"^<%filezillog%^|find /n /v ""') do set ttl=%%a

echo counted total: %ttl%
>%base%.x echo %ttl% %date% %time%
set /a dif=ttl-k
echo diff: %dif% since last checked: %ld% %lt%
::========= end
test it independent of your script - it shouldwork, as it did on my end. I added instances of "retr ortnew.txt" to filezillog and it managed to accumulate them into count.


Report •

#7
November 19, 2015 at 20:26:40
Thanks nbrane
Already I see a possible conflict though in my Batch file I aready use the variable for filezillorlog as below

set filezilllog="\\%computername%\filezilla-Logs\fzs-%YEAR%-%Month%-%Day%.log"

Oh I see it is spelled differently so should be ok
my variable is %filezilllog%
The one in your new code is %filezillog%

But this might cause confussion.

Michelle

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb


Report •

#8
November 19, 2015 at 21:26:14
Hmm something is working, but I am seeing no resuts in the couter output except for -20

RESULT:
counted total:
diff: -20 since last checked:


I am including a sample of my log below maybe it is the format of the search that is not able to parse my logfile ?

Michelle xoxoxox

(000077) 20/11/2015 03:01:20 - autoclean (192.168.2.1)> 230 Logged on
(000077) 20/11/2015 03:01:20 - autoclean (192.168.2.1)> TYPE I
(000077) 20/11/2015 03:01:20 - autoclean (192.168.2.1)> 200 Type set to I
(000077) 20/11/2015 03:01:20 - autoclean (192.168.2.1)> CWD batch
(000077) 20/11/2015 03:01:20 - autoclean (192.168.2.1)> 250 CWD successful. "/batch" is current directory.
(000077) 20/11/2015 03:01:20 - autoclean (192.168.2.1)> PASV
(000077) 20/11/2015 03:01:20 - autoclean (192.168.2.1)> 227 Entering Passive Mode (192,168,2,10,8,12)
(000077) 20/11/2015 03:01:20 - autoclean (192.168.2.1)> RETR Autoclean.new
(000077) 20/11/2015 03:01:20 - autoclean (192.168.2.1)> 150 Connection accepted
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 226 Transfer OK
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> PASV
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 227 Entering Passive Mode (192,168,2,10,8,13)
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> RETR ortnew.txt
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 150 Connection accepted
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 226 Transfer OK
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> CWD flags
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 250 CWD successful. "/batch/flags" is current directory.
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> PASV
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 227 Entering Passive Mode (192,168,2,10,8,14)
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> RETR Autoclean.chksum
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 150 Connection accepted
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 226 Transfer OK
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> PASV
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 227 Entering Passive Mode (192,168,2,10,8,15)
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> RETR version
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 150 Connection accepted
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 226 Transfer OK
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> CWD ../apps
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 250 CWD successful. "/batch/apps" is current directory.
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> PASV
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 227 Entering Passive Mode (192,168,2,10,8,16)
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> RETR Contig.exe
(000077) 20/11/2015 03:01:23 - autoclean (192.168.2.1)> 150 Connection accepted
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 226 Transfer OK
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> CWD ../setup
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 250 CWD successful. "/batch/setup" is current directory.
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> CWD ../Mbar
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 250 CWD successful. "/batch/Mbar" is current directory.
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> CWD Data
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 250 CWD successful. "/batch/Mbar/Data" is current directory.
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> CWD Configuration
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 250 CWD successful. "/batch/Mbar/Data/Configuration" is current directory.
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> CWD ../../imageformats
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 250 CWD successful. "/batch/Mbar/imageformats" is current directory.
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> CWD ../Languages
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 250 CWD successful. "/batch/Mbar/Languages" is current directory.
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> CWD ../Plugins
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 250 CWD successful. "/batch/Mbar/Plugins" is current directory.
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> CWD ../
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 250 CWD successful. "/batch/Mbar" is current directory.
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> TYPE A
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 200 Type set to A
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> PASV
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 227 Entering Passive Mode (192,168,2,10,8,17)
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> LIST
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 150 Connection accepted
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 226 Transfer OK
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> TYPE I
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 200 Type set to I
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> QUIT
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> 221 Goodbye
(000077) 20/11/2015 03:01:31 - autoclean (192.168.2.1)> disconnected.

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb

message edited by Ortorea


Report •

#9
November 20, 2015 at 17:15:17
First of all, before testing, delete "ortnew.x". I think you have old data junk laying around in there. second, my mistake (again), add /I (ignore case option) to the "find", as in this update:

for /f "tokens=1 delims=[]" %%a in ('find /I "retr %base%.txt"^<%filezilllog%^|find /n /v ""') do set ttl=%%a

My test with your data worked ok. I added junk and target-string mixed and it accumulated correctly into ortnew.x Sorry about the misspells and option deficit!



Report •

#10
November 21, 2015 at 09:47:46
Hi nrane,
Maybe it is partly my fault too because the log data is stored in a filename by date for example: fzs-2015-11-13.log

But the log is stored in a VAR like this:
set filezilllog="\\%computername%\filezilla-Logs\fzs-%YEAR%-%Month%-%Day%.log"

Just so were clear :o)

I will make the code changes and test ....

Michelle

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb


Report •

#11
November 21, 2015 at 11:28:58
I made a new test file see below, but still does not seem to find anything the base.x file has this in fact in the file:

" 21/11/2015 19:45:04.47"

Without quotes

START

@echo off & setlocal enabledelayedexpansion
set filezilllog="\\%computername%\filezilla-Logs\fzs-%YEAR%-%Month%-%Day%.log"
:scrat
:: ---------------------- FINDING DATE -----------------------

@For /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do @(
Set Day=%%A
Set Month=%%B
Set Year=%%C
)

set base=ortnew
if not exist %base%.x >%base%.x echo.
(for /f "tokens=1-4" %%a in (%base%.x) do (
set k=%%a
set ld=%%~c
set lt=%%~d
)) 2>nul

for /f "tokens=1 delims=[]" %%a in ('find /I "retr %base%.x"^<%filezilllog%^|find /n /v ""') do set ttl=%%a

echo counted total: %ttl%
:: SayStatic %filename% counted total: %ttl%

>%base%.x echo %ttl% %date% %time%
set /a dif=ttl-k
echo diff: %dif% since last checked: %ld% %lt%
:: SayStatic %filename% Download diff: %dif% since last checked: %ld% %lt%

pathping 127.0.0.1 -n -q 1 -p 5000 >nul 2>&1
cls
goto :scrat


END

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb

message edited by Ortorea


Report •

#12
November 21, 2015 at 11:59:18
I got the LOG output and think I see what is going wrong:

LOG OUTPUT:

D:\Program Files\Automation>goto :scrat

D:\Program Files\Automation>set base=ortnew

D:\Program Files\Automation>if not exist ortnew.x echo.1>ortnew.x

D:\Program Files\Automation>(for /F "tokens=1-4" %a in (ortnew.x) do (
set k=%a
set ld=%~c
set lt=%~d
) ) 2>nul

D:\Program Files\Automation>(
set k=21/11/2015
set ld=
set lt=
)

D:\Program Files\Automation>for /F "tokens=1 delims=[]" %a in ('find /I "retr or
tnew.txt"<"\\JOANNA1997\filezilla-Logs\fzs---.log"|find /n /v ""') do set ttl=%a

The system cannot find the file specified.

D:\Program Files\Automation>echo counted total:
counted total:

D:\Program Files\Automation>echo 21/11/2015 19:56:44.44 1>ortnew.x

D:\Program Files\Automation>set /a dif=ttl-k

D:\Program Files\Automation>echo diff: -21 since last checked:
diff: -21 since last checked:

D:\Program Files\Automation>pathping 127.0.0.1 -n -q 1 -p 5000 1>nul 2>&1

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb


Report •

#13
November 21, 2015 at 12:12:17
Making progress it was looking for ortnew.x instead or ortnew.txt

New Logfile below

D:\Program Files\Automation>goto :scrat

D:\Program Files\Automation>set filezilllog="\\JOANNA1997\filezilla-Logs\fzs-201
5-11-21.log"

D:\Program Files\Automation>set base=ortnew

D:\Program Files\Automation>if not exist ortnew.x echo.1>ortnew.x

D:\Program Files\Automation>(for /F "tokens=1-4" %a in (ortnew.x) do (
set k=%a
set ld=%~c
set lt=%~d
) ) 2>nul

D:\Program Files\Automation>(
set k=3
set ld=20:10:20.41
set lt=
)

D:\Program Files\Automation>for /F "tokens=1 delims=[]" %a in ('find /I "retr or
tnew.txt"<"\\JOANNA1997\filezilla-Logs\fzs-2015-11-21.log"|find /n /v ""') do se
t ttl=%a

D:\Program Files\Automation>set ttl=1

D:\Program Files\Automation>set ttl=2

D:\Program Files\Automation>set ttl=3

D:\Program Files\Automation>echo counted total: 3
counted total: 3

D:\Program Files\Automation>echo 3 21/11/2015 20:10:27.27 1>ortnew.x

D:\Program Files\Automation>set /a dif=ttl-k

D:\Program Files\Automation>echo diff: 0 since last checked: 20:10:20.41
diff: 0 since last checked: 20:10:20.41

D:\Program Files\Automation>pathping 127.0.0.1 -n -q 1 -p 5000 1>nul 2>&1

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb


Report •

#14
November 21, 2015 at 12:30:57
It's Working, thanks nbrane yippie

Michelle

I modified it to count up to 3 files and also do a total counter register to keep track over times and dates from a separate log file.

:: SNIPPET START --------------------------------------------------

:: ************ SCRATCH 0 FILE TO BE CALLED ****************
:scrat
set base=ortnew
if not exist %base%.x >%base%.x echo.
(for /f "tokens=1-4" %%a in (%base%.x) do (
set k=%%a
set ld=%%~c
set lt=%%~d
)) 2>nul

for /f "tokens=1 delims=[]" %%a in ('find /I "retr %base%.txt"^<%filezilllog%^|find /n /v ""') do set ttl=%%a

if "%ttl%" gtr "0" echo %base%.txt Downloads counted total: "%ttl%"
if "%offs%"=="true" SayStatic %base%.txt counted total: %ttl%

>%base%.x echo %ttl% %date% %time%
set /a dif=ttl-k
echo %base%.txt diff: %dif% since last checked: %ld% %lt%
if "%offs%"=="true" SayStatic %base%.txt Download diff: %dif% since last checked: %ld% %lt%
set baset=%ttl%
goto :end
:: ************ SCRATCH 0 FILE WAS CALLED ****************

:: ************ SCRATCH 1 FILE TO BE CALLED ****************
:scrat1
set base1=autoclean
if not exist %base1%.x >%base1%.x echo.
(for /f "tokens=1-4" %%a in (%base1%.x) do (
set k=%%a
set ld=%%~c
set lt=%%~d
)) 2>nul

for /f "tokens=1 delims=[]" %%a in ('find /I "retr %base1%.new"^<%filezilllog%^|find /n /v ""') do set ttl=%%a

if "%ttl%" gtr "0" echo %base1%.new Downloads counted total: "%ttl%"
if "%offs%"=="true" SayStatic %base1%.new counted total: %ttl%

>%base1%.x echo %ttl% %date% %time%
set /a dif=ttl-k
echo %base1%.new diff: %dif% since last checked: %ld% %lt%
if "%offs%"=="true" SayStatic %base1%.new Download diff: %dif% since last checked: %ld% %lt%
set base=%ttl%
goto :end
:: ************ SCRATCH 1 FILE WAS CALLED ****************

:: ************ SCRATCH 2 FILE TO BE CALLED ****************
:scrat2
set base2=Clean6
if not exist %base2%.x >%base2%.x echo.
(for /f "tokens=1-4" %%a in (%base2%.x) do (
set k=%%a
set ld=%%~c
set lt=%%~d
)) 2>nul

for /f "tokens=1 delims=[]" %%a in ('find /I "retr %base2%.new"^<%filezilllog%^|find /n /v ""') do set ttl=%%a

if "%ttl%" gtr "0" echo %base2%.new Downloads counted total: "%ttl%"
if "%offs%"=="true" SayStatic %base2%.new counted total: %ttl%

>%base2%.x echo %ttl% %date% %time%
set /a dif=ttl-k
echo %base2%.new diff: %dif% since last checked: %ld% %lt%
if "%offs%"=="true" SayStatic %base2%.new Download diff: %dif% since last checked: %ld% %lt%
set base=%ttl%
goto :end
:: ************ SCRATCH 2 FILE WAS CALLED ****************
:counter
echo.
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:: #### STRIP OUT ANY NEG(-)ATIVE SUB FROM COUNTER ####
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if not exist %totaldwnlds% set var1=0
if not exist %totaldwnlds% goto :add
:: ----------------------------------
set /p var1=< %totaldwnlds%
:add
SET result=%var1:-= %
echo.
echo Result equals %result%
if %Result% gtr %var1% set vart=A Numerical Error Has Been Corrected.
if %Result% gtr %var1% >> %ftplog% echo A Numerical Error Has Been Corrected. Time:%time% Date:%date%
if %Result% equ %var1% set vart=The Sums R. Working Correctly.
echo.
if not "%Result%" equ "%var1%" if "%var1%" geq "1" > %totaldwnlds% echo %result%
:: ----------------------------------
if not "%Vart%" == "" echo %vart%
echo.
if "%dif%" gtr "%Vart%" SayStatic %vart%
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:: #### STRIP OUT ANY NEG(-)ATIVE SUB FROM COUNTER ####
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:: #### THIS COUNTER COUNTS TOTAL NUMBER OF DOWNLOAD'S ####
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set /a var1=%result%
if "%dif%" gtr "0" set /a var2=%var1%+%dif%
if "%dif%" equ "0" set var2=%var1%
if "%dif%" geq "%result%" > %totaldwnlds% echo %var2%
set dif=0
echo The Total Down-loads so Far are %var2%
if "%dif%" gtr "0" >> %ftplog% echo The Total Down-loads so Far are %var2% Time:%time% Date:%date%
if "%dif%" gtr "0" SayStatic The Total Down-loads so Far are %var2%
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:end
pathping 127.0.0.1 -n -q 1 -p 5000 >nul 2>&1

:: SNIPPET END -----------------------------------------------------

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb

message edited by Ortorea


Report •

#15
November 23, 2015 at 16:36:45
OOOOPS, I thought it was all good but today when I checked the server my SUMS stored in the text files had taken a twist and became a MINUS (-) number I can not figure out what caused it because yesterday I had "12" and today "-12" ?

I am looking at a way to remove the minus sign if it happens again, might have been a glitch but it really screws up the counting I came across this bit of code:

:: SET _test=-12
:: SET _result=%_test:~1,6%
:: ECHO %_result%

This removes a first character of a string but what I need is a CHECK to see if it has a leading "-" without quotes before a number to remove it from the variable, any idea's ?

Michelle


PS, LOL I found my answer

:: REFERENCES
:: REMOVE UNWANTED MINUS (-) sign from numerical VAR
echo.
SET _test=-12
SET _result=%_test:-= %
ECHO %_result% was %_test%
echo.
pause

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb

message edited by Ortorea


Report •


Ask Question