I'm new to Batch and have created a script for work, whilst learning as i go along. (this is not a very elegant script, but it does the job... more or less)
Anyway the idea of the script is to run a program cvimp.exe on a lost of files (this program doesnt dump memory which is why i need to split it up into batches)
This is the batch file so far:
Code: Select all
@ECHO OFF
SETLOCAL enabledelayedexpansion
CALL:resumeParse
:resumeParse
ECHO _______________________ BULK RESUME PARSING - LOG _______________________ > parserStatistics.txt
ECHO. >> parserStatistics.txt
:: Loops through files in file list and calls parser.bat with the file
FOR /F %%a IN (C:\Users\owain.esau\Desktop\BulkResumeParser\dir_file.txt) do (
:: Variable declaration
SET a=%a: =%
SET file=%%a
SET timeBefore=%time%
timeout 2
FOR /F %%b IN (C:\Users\owain.esau\Desktop\BulkResumeParser\dir_file_parsed.txt) do (
SET b=%b: =%
SET fileC=%%b
IF !file! == !fileC! (
ECHO [ERR] This file has already been parsed
ECHO [ERR] Re-Parsing this will result in duplicate data
ECHO [ERR] Please remove entry from: dir_file.txt
ECHO [ERR] Program will now exit
ECHO [ERR] Resume parser encountered errors file >> parserStatistics.txt
timeout 10 && EXIT
)
)
:: Call cv importer and wait for end
::START /WAIT parser.bat !file!
ECHO [*] Calling cvimporter on file: !file! :: !timeBefore!
CALL:loggingBefore !timeBefore! !file!
SET timeAfter=%time%
CALL:loggingAfter !timeAfter! !file!
ECHO.
ECHO [+] Cvimporter completed successfully on !file! :: !timeAfter!
ECHO.
ECHO [*] Removing file from file list
TYPE dir_file.txt | findstr !file! >> dir_file_parsed.txt
ECHO.
ECHO [*] Proceeding to next file
)
ECHO [+] Resume Parser Script ran without errors >> parserStatistics.txt
ECHO. >> parserStatistics.txt
ECHO [+] Resume Parser Script ran without errors
CALL:logInput
EXIT /B
:LogInput
set /p logOpen="Would you like to open the log file (Y / N)? "
If /I "%logOpen%"=="y" (
start /WAIT notepad.exe parserStatistics.txt
EXIT
)
If /I "%logOpen%"=="n" (
ECHO.
ECHO [*] Script will exit in 5 seconds
timeout 5 && exit
) else (
ECHO.
ECHO Invalid Input
CALL:logInput
)
EXIT /B
:loggingBefore
ECHO. >> parserStatistics.txt
ECHO. >> parserStatistics.txt
ECHO. >> parserStatistics.txt
ECHO !file! :: !timeBefore! - !timeAfter! >> parserStatistics.txt
ECHO. >> parserStatistics.txt
ECHO ######################################################################### >> parserStatistics.txt
ECHO. >> parserStatistics.txt
ECHO. >> parserStatistics.txt
ECHO Parser starting time: !timeBefore! >> parserStatistics.txt
::systeminfo | find "Available Physical Memory" >> parserStatistics.txt
ECHO. >> parserStatistics.txt
EXIT /B
:loggingAfter
ECHO. >> parserStatistics.txt
ECHO Parser ending time: !timeAfter! >> parserStatistics.txt
::systeminfo | find "Available Physical Memory" >> parserStatistics.txt
ECHO. >> parserStatistics.txt
EXIT /B
with the two time variables:
SET timeBefore=%time%
SET timeAfter=%time%
The time is the same for every entry in the generated log file.
I was also wanting to have the script pause for 30 minutes or so if the available memory got too low, but i cant figure out how to put the following command into a variable:
systeminfo | find "Available Physical Memory"
Any help on this would be much appreciated!