1
votes

I am write aws s3 data backup inside batch file as bellow

test.bat

@echo off

echo ---------Data synchronization START at %date% %time%------------  

:loop
    aws s3 sync D:\backup s3://upload --exclude "*.jpg"


IF %ERRORLEVEL% NEQ 0 GOTO :loop
echo ---------Data synchronization END at %date% %time%------------  

this batch file run using run.bat file that look like bellow

run.bat

@echo off
start  test.bat
timeout /t 10
taskkill /fi "imagename eq aws.exe" /f
taskkill /fi  test.bat /f

I want to stop aws sync and close test.bat window after 10s run test.bat file i try to stop aws sync process using taskkill /fi "imagename eq aws.exe" /f and close test.bat window using taskkill /fi test.bat /f

but i can't stop aws sync process and close test.bat window

1
Why do you want to kill aws and the batch? this line IF %ERRORLEVEL% NEQ 0 GOTO :loop is not supposed to end the loop after the sync is finished? have you tried to kill first test.bat ? - Paul
yes i try but i can't kill test.bat - DD Dev

1 Answers

0
votes

Add title to test.bat then taskill with the filter of windowtitle

@echo off
setlocal
title test.bat
echo ---------Data synchronization START at %date% %time%------------  
for /L %%i in (1,1,1000)
aws s3 sync D:\backup s3://upload --exclude "*.jpg"
IF %ERRORLEVEL% NEQ 0 GOTO :loop
echo ---------Data synchronization END at %date% %time%------------  
exit /b 0

run.bat

@echo off
start "" test.bat
timeout /t 10 >nul
taskkill /f /im cmd.exe /fi "windowtitle eq test.bat"
taskkill /f /im aws.exe /fi "imagename eq aws.exe"

you could also add a stop.tmp after timeout and check if file exist and then exit /b 0

@echo off
setlocal
title test.bat
echo ---------Data synchronization START at %date% %time%------------  
for /L %%i in (1,1,1000)
aws s3 sync D:\backup s3://upload --exclude "*.jpg"

IF EXIST stop.tmp del stop.tmp &exit /b 0
IF %ERRORLEVEL% NEQ 0 GOTO :loop
echo ---------Data synchronization END at %date% %time%------------  
exit /b 0

run.bat with stop.tmp

@echo off
start "" test.bat
timeout /t 10 >nul
copy nul stop.tmp