Batch File not running in the AM hours

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jasieltego
Posts: 1
Joined: 12 May 2021 14:31

Batch File not running in the AM hours

#1 Post by jasieltego » 12 May 2021 15:29

Hi All,

I have an occurring issue. I have setup task scheduler to run a batch file at 12am and every hour after that.
I have setup the task to run as SYSTEM, Highest Privilege, run whether logged on or off and the Batch file does not run from 12am-10am. It's recurring behavior, it never runs from midnight to 10am. However at 11am it will run, and continue running every hour until 11PM. The computer does not go to sleep, played with all the options in task scheduler to wake it up if it needs too. However issue still occurs. I have tried running it as my local admin account and still not working.
At this point, I believe it's an issue with the code in the batch script because I have even gone as far as creating the batch file to an exe file.

The batch file is loading jmeter, utility to load test sites. Is there any thing in the code that prevents it from running at certain times of the day. Can you please help me out or point me in the right direction?
I believe it has to be a code issue because , when I test for example to open a notepad at 12am and every hour after it, it does it.

Code: Select all

@ECHO OFF
setlocal EnableExtensions DisableDelayedExpansion
set name=%DATE:~4%-%DATE:~-7,2%-%DATE:~-10,2%
echo %name%

IF NOT EXIST C:\AA\Per\Reports\%name% (
echo "create new"
mkdir C:\AA\Per\Reports\%name%
mkdir C:\AA\Per\Reports\%name%\MLReports
)
"C:\Program Files\apache-jmeter-5.3\bin\jmeter" -n -t C:\AA\Per\JMX\mytest.jmx -l C:\AA\Per\Reports\%name%\Report-%date:~10,4%-%date:~7,2%-%time:%time:~6,2%.jtl -e -o C:\AA\Per\Reports\%name%\MLReports\%date:~10,4%-%date:~4,2%-%date:~7,2%_%time:~0,2%-%time:~3,2%-%time:~6,2%
Last edited by Squashman on 13 May 2021 07:59, edited 1 time in total.
Reason: MOD EDIT: Please use CODE tags.

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

Re: Batch File not running in the AM hours

#2 Post by ShadowThief » 13 May 2021 07:51

When the value of %TIME% is between 1:00 and 9:59 AM, the hour is prefixed with a space. Since your output path is unquoted, your reports aren't being sent to the correct location.

You've got a couple options here:
1. Use quotes

Code: Select all

"C:\Program Files\apache-jmeter-5.3\bin\jmeter" -n -t C:\AA\Per\JMX\mytest.jmx -l "C:\AA\Per\Reports\%name%\Report-%date:~10,4%-%date:~7,2%-%time:%time:~6,2%.jtl" -e -o "C:\AA\Per\Reports\%name%\MLReports\%date:~10,4%-%date:~4,2%-%date:~7,2%_%time:~0,2%-%time:~3,2%-%time:~6,2%"
2. Use wmic to generate a locale-independent timestamp that has proper zero-padding on the hour value

Code: Select all

@echo off

for /f "tokens=2 delims==" %%A in ('wmic os get localdatetime /value ^| find "="') do set "timestamp=%%A"
set "name=%timestamp:~0,4%-%timestamp:~4,2%-%timestamp:~6,2%"
set "ftime=%timestamp:~8,2%-%timestamp:~10,2%-%timestamp:~12,2%"
IF NOT EXIST "C:\AA\Per\Reports\%name%" (
	echo "create new"
	mkdir "C:\AA\Per\Reports\%name%"
	mkdir "C:\AA\Per\Reports\%name%\MLReports"
)
echo "C:\Program Files\apache-jmeter-5.3\bin\jmeter" -n -t C:\AA\Per\JMX\mytest.jmx -l C:\AA\Per\Reports\%name%\Report-%name%-%ftime:~0,5%.jtl" -e -o "C:\AA\Per\Reports\%name%\MLReports\%name%-%ftime%"
It's also worth mentioning that you've got a stray %time: in the -l value, so I don't know how your code is working at all. Also, I don't know what %date% looks like to you, but it's different from mine so I just made an educated guess about what you wanted it to look like.

Post Reply