Home > Software design >  BATCH process in Scheduled Task runs twice, one immediatly after another by miliseconds
BATCH process in Scheduled Task runs twice, one immediatly after another by miliseconds

Time:12-23

I have a Scheduled Task which runs, every 15 minutes, a very very quick BATCH process. This first "FILE1.bat" process calls another one like this: "FILE2.bat" >> PATH\winscp_TODAYSDATE.txt This way I can get all the output from the second into a TXT "log file". FILE2.bat just copies files to a "DONE" folder and sends them via WINSCP to a provider, with a mput -delete, which deletes the files once successfully sent.

For some reason unknown to me, the TASK (not sure if the task itself, the FILE1 or the FILE2) runs twice (even thrice), one immediatly after another just by some miliseconds, as shown in the next text. This is the result when there are no files to be processed:

*************************************************************
******** HORA DEL REGISTRO: 21/12/2022 -  0:05:01,26 ********
*************************************************************
    ***** SIN ficheros TXT para procesar, se ha omitido el proceso y no se envia email
Success - No files to process - FICHEROS ENVIADOS: NO FILES
*************************************************************
******** HORA DEL REGISTRO: 21/12/2022 -  0:05:01,77 ********
*************************************************************
    ***** SIN ficheros TXT para procesar, se ha omitido el proceso y no se envia email
Success - No files to process - FICHEROS ENVIADOS: NO FILES
*************************************************************
******** HORA DEL REGISTRO: 21/12/2022 -  0:20:00,97 ********
*************************************************************
    ***** SIN ficheros TXT para procesar, se ha omitido el proceso y no se envia email
Success - No files to process - FICHEROS ENVIADOS: NO FILES
*************************************************************
******** HORA DEL REGISTRO: 21/12/2022 -  0:20:01,26 ********
*************************************************************
    ***** SIN ficheros TXT para procesar, se ha omitido el proceso y no se envia email
Success - No files to process - FICHEROS ENVIADOS: NO FILES
*************************************************************
******** HORA DEL REGISTRO: 21/12/2022 -  0:20:01,76 ********
*************************************************************
    ***** SIN ficheros TXT para procesar, se ha omitido el proceso y no se envia email
Success - No files to process - FICHEROS ENVIADOS: NO FILES

But when there are files to be processed, this happens (not always, though):

*************************************************************
******** HORA DEL REGISTRO: 21/12/2022 - 14:05:01,47 ********
*************************************************************
    ***** Se comprueba si hay ficheros TXT que existan para procesar: SI
    ***** Se copian los ficheros que existan para enviar antes de enviarlos a la subcarpeta COPIAS, sobreescribiendo
l:\entradas\ALS20221221135146008008649.txt
*************************************************************
******** HORA DEL REGISTRO: 21/12/2022 - 14:05:02,47 ********
*************************************************************
    ***** Se comprueba si hay ficheros TXT que existan para procesar: SI
    ***** Se copian los ficheros que existan para enviar antes de enviarlos a la subcarpeta COPIAS, sobreescribiendo
l:\entradas\ALS20221221135146008008649.txt
l:\entradas\ALS20221221135434008008649.txt
l:\entradas\ALS20221221135534008008649.txt
l:\entradas\ALS20221221135809008008649.txt
        4 archivo(s) copiado(s).
    ***** Se ejecuta WINSCP con los parametros necesarios
Connecting to x-x-x-x-x-x-x-x-x-xguro.com ...
Connected
Starting the session...
Session started.
Active session: [1] copx-x-x-xx-x-x-x-x-x-x-x-x-xguro.com
l:\entradas
/ENTRADAS
ALS20221221135146008008649.txt |          14 KB |    0,0 KB/s | binary | 100%
ALS20221221135434008008649.txt |           1 KB |    5,6 KB/s | binary | 100%
ALS20221221135534008008649.txt |           1 KB |    6,2 KB/s | binary | 100%
ALS20221221135809008008649.txt |           1 KB |    6,8 KB/s | binary | 100%
/SALIDAS
l:\SALIDAS
No file matching '*' found.
Session 'copx-x-x-xx-x-x-x-x-x-x-x-x-xguro.com' closed.
No session.
    ***** Se revisa si ha habido errores en el envio. ERRORCODE:0
    ***** Envio sin errores: Se omite el email
    ***** Resultado del envio por FTP
Success - The files were uploaded successfully. - FICHEROS ENVIADOS: SI
*************************************************************
******** HORA DEL REGISTRO: 21/12/2022 - 14:20:01,88 ********
*************************************************************
    ***** SIN ficheros TXT para procesar, se ha omitido el proceso y no se envia email
Success - No files to process - FICHEROS ENVIADOS: NO FILES

The files are successfully sent, fortunately and so far, but it fills the log and I'm not at ease about it...

I have looked as hard as I could, unable to find reason or solution to this behavior. I am attaching, too, the XML of the exported TASK.

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2022-10-28T12:14:19.6597722</Date>
    <Author>SEFRISA\eqm</Author>
    <URI>\_GyV FTP Logifrio_</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <Repetition>
        <Interval>PT15M</Interval>
        <StopAtDurationEnd>false</StopAtDurationEnd>
      </Repetition>
      <StartBoundary>2022-10-28T12:05:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-21-1834156839-169156998-926709054-1284</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>StopExisting</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>false</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>GyV_Reg.bat</Command>
      <WorkingDirectory>C:\TareasFTP_Logifrio\</WorkingDirectory>
    </Exec>
  </Actions>
</Task>

I just looked for a solution and tried changing the task options, but none worked and even some of the options were disabling the proper execution of the task.

EDIT: @Mofi, here you have FILE1 (GyV_Reg.bat) and FILE2 (gyv.bat). I believe I tried, at some point, running the task as you mention, with %SystemRoot%\System32\cmd.exe, but unsuccessfully. I'll investigate more about the /D /C modifiers. Thank you very much

Gyv_Reg.bat

@echo off
if not exist l: net use l: /persistent:yes \\servidor2k9\logifrio$
set day=           
  • Related