Windows Scheduler - Script Execution Error - windows

I'm trying to set up Windows Task Scheduler to run the upload_xml.cmd script below:
Inside this script I call several other files that have FTP commands, but when I run the task scheduler I configured, it only runs until step 2. How can I solve this problem?
:Step 1
Echo step 1 - Check for xml files to process
Netsh advfirewall set allprofiles state off
Of xmls.list /f/q
Dir /s/b C:\xml\UPLOAD\*.xml xmls.list
Find /c ".xml xmls.list
If% errorlevel% equ 1 goto Exit
Echo step 1 - Files found
: Step2
Echo step 2 - run the ftp script to check if the connection exists
In10xml_connect /f/q
Ftp -s: download_connect.ftpget xx.xxx.xxx.xx
If not exist in10xml_connect goto Exit
Echo step 2 - SUCCESSFUL CONNECTION
: Step3
Echo step 3 - run the ftp script to check if you can send the files
In10xml_loader.lock /f/q
Ftp -s: download_lock.ftpget xx.xxx.xxx.xx
If exist in10xml_loader.lock goto Exit
Echo step 3 - UPLOAD CAN CONTINUE

Related

Running batch script with two msiexec commands causes finishing script just after finishing first command

I am trying to run batch script from jenkins job which has two msiexec commands one for uninstallation and other for installation.
This script is on github so jenkins job clone the repo and then run the script
Jenkins job start execution of second msiexec (installation) command but it ends immediately.If i open Job console i can see message "Process leaked file descriptors." and job status : Success
If i run The same script through cmd without jenkins it is working fine.
setlocal enabledelayedexpansion
IF EXIST "directory path" (
msiexec /uninstall {Product ID} /qb
)
pushd \\shared drive
IF EXIST "directory path" (
msiexec /i "path to exefile" /qb
popd
exit 0
)
ELSE (
ECHO Setup Not Found in current
exit 0
)
The keyword ELSE must be on same line as ) of TRUE branch of IF condition separated from ) by a space character. The ELSE on a separate line is interpreted like name of a console application to run.
if exist "directory path" (
%SystemRoot%\System32\msiexec.exe /uninstall {Product ID} /qb
)
pushd "\\ComputerName\ShareName\"
if exist "directory path" (
%SystemRoot%\System32\msiexec.exe /i "path to exefile" /qb
) else (
echo Setup not found in %CD%.
)
popd
exit /B 0
Hint: For debugging a batch file run it from within a command prompt window and not with double clicking on it after removing or commenting all lines containing echo off. And don't use EXIT without /B as this results always in exiting entire command process and not only in exiting just processing of current batch file. Debugging a batch file in a command prompt window becomes difficult if the batch file contains EXIT without /B and this command is really executed on running the batch file because error messages output during running the batch file can't be seen in this case.

Error level not changing when file is ran with psexec

I have one piece of code that is behaving differently when I ran it on server and when I ran it with psexec. I'm actually trying to determent is computer offline, but that is not question here. Problem is that when I run this command directly on server errorlevel is changing to 1, because pc is online. But when I use psexec to run file with same commands on that server errorelevel is not changing it stays 0. I cant find any explanations on internet.
echo %errorlevel%
ping -n 1 machine | findstr "not" > nul
IF %errorlevel%==0 (
echo test
)
echo %errorlevel%
pause
What you show is not a command, but a batch file, say ping_machine.cmd. To call it from psexec the command line would be something like psexec \\server cmd /c ping_machine.cmd. If I guessed wrong you may stop reading the rest of this answer now (and next time post enough relevant context so that one doesn't have to guess).
Problem is that cmd /c returns the exit code of ping_machine, but the batch file does not explicitly set an exit code, so it returns 0 by default. This can be verified at the cmd prompt with the following 2 runs - note that inside the batch file you see the same/correct errorlevels, but cmd /c returns 0.
C:\etc>ping_machine
0
1
Press any key to continue . . .
C:\etc>echo %errorlevel%
1
C:\etc>cmd /c ping_machine
0
1
Press any key to continue . . .
C:\etc>echo %errorlevel%
0
To have cmd /c behave as you expect (and in turn psexec as well), add the following line at the end of the batch file to return the respective errorlevel (this works because neither echo nor pause modify the errorlevel, otherwise you'd have to save it in a temp variable for later use).
exit /b %errorlevel%
There it is. When I run this batch file locally errorlevel is changed to 9009. When I use psexec \\computername -f -c pathToFile , error code is staying 0.
#echo off
echo %errorlevel%
pin 234343
echo %errorlevel%
pause

Configuring Jenkins CI Job and FreeFileSync Batch Using Windows Batch Command

I have just setup Jenkins CI as my build server but I have an issue with correctly configuring FreeFileSync batch file and the command that calls the batch file used for deploying the application after building it.
call Path\deploy.ffs_batch
The build console displays success if deploy.ffs_batch execution was successful. But in the case of where the deploy.ffs_batch settings was wrong for example wrong path as destination, the build never stops and console log spinner on Hudson keeps spinning without stopping and without giving any information.
What I have tried is adding this command below the one above to the Windows batch command:
if %errorlevel% neq 0 exit %errorlevel%
But build still not happy (spinner keeps spinning).
However, when I check the log folder for FreeFileSync batch file, I see this:
[03:52:46 PM] Info: Starting comparison
[03:52:46 PM] Error: Cannot find the following folders:
D:\Deploy\1\Dev
You can ignore this error to consider each folder as empty. The folders then will be created automatically during
synchronization.
[03:52:46 PM] Error: Synchronization stopped
I do understand the error and I can fix it. But I really do not want to always look in the log folder for answers when this occurs. So my question is how can I output the FreeFileSync error on Hudson console log and also abort the build using Windows batch command?
I discovered that I was missing one vital step when an error occurred and that is stopping the synchronization when an error occurs to prevent hudson job build from running endlessly.
After setting this to stop, I update my batch command to:
cd "Path\FreeFileSync\"
FreeFileSync.exe "Path\deploy.ffs_batch"
echo.
echo.
echo ===============================================================================
echo ##### Results :
echo ===============================================================================
echo.
echo.
#echo off
for /f "delims=" %%x in ('dir "Path\logs\" /od /b') do set recent=%%x
echo.
echo ===============================================================================
if %ERRORLEVEL% == 0 goto SYNCSUCCESS
if %ERRORLEVEL% == 1 goto SYNCWARNINGS
if %ERRORLEVEL% == 2 goto SYNCERRORS
if %ERRORLEVEL% == 3 goto SYNCABORTED
goto SYNCFAIL
:SYNCFAIL
echo ##### FreeFileSync failed.
type "path\logs\%recent%"
exit 2
:SYNCSUCCESS
echo ##### FreeFileSync completed successfully!
exit 0
:SYNCWARNINGS
echo ##### FreeFileSync completed, but with warnings.
type "path\logs\%recent%"
exit 1
:SYNCERRORS
echo ##### FreeFileSync completed, but with warnings.
type "path\logs\%recent%"
exit 2
:SYNCABORTED
echo ##### FreeFileSync aborted.
type "path\logs\%recent%"
exit 3
Please note: Run minimized checkbox needs to be checked also to avoid the job from running continously.
The job runs and stops when there is an error.

In Windows, how would I create a batch file that opens 2 command windows with a specific Java program?

I am trying to create a batch file that will reopen my KnockKnockClient and KnockKnockServer programs , get them started.
So far , my batch file looks like this :
#echo off
setlocal
start cmd
start java KnockKnockServer
ping 192.0.2.2 -n 1 -w 5000 > null
start /wait java KnockKnockClient
if errorlevel 1 goto retry
echo Finished successfully
exit
:retry
Also, suppose that I want it to restart so that the CMD window with the KnockKnockClient is active. Is that possible ?
any tips appreciate, thank
"start" itself invokes cmd.
you don't need to give "start cmd"
Maybe your directory path should be varied. (locate correct path of your program)

Task Scheduler Batch not fully working

I have an issue with my batch script that's configured to run every 6 hours every day through Windows Task Scheduler. The batch does it's job if I run the Schedule or batch manually, but not when it's run automatically.
Here's how the batch looks like:
#echo off
cd "C:\Program Files (x86)\Steam\SteamApps\common\Arma 2 CO\instance_11_Chernarus"
cscript /nologo "C:\Users\Administrator\Desktop\Batch Jobs\DayZ Epoch\timezone.vbs" > newfile 2>> error.log
del config.cfg
ren newfile config.cfg
ping 127.0.0.1 -n 3 >NUL
cd "C:\Program Files (x86)\Steam\SteamApps\common\Arma 2 CO"
start "arma2" /min "C:\Program Files (x86)\Steam\SteamApps\common\Arma 2 CO\Expansion\beta\arma2oaserver.exe" -port=2302 "-config=instance_11_Chernarus\config.cfg" "-cfg=instance_11_Chernarus\basic.cfg" "-profiles=instance_11_Chernarus" -name=instance_11_Chernarus "-mod=#DayZ_Epoch;#DayZ_Epoch_Server;"
cd C:\Users\Administrator\Desktop\BEC\
start C:\Users\Administrator\Desktop\BEC\bec.exe -f Config.cfg
Now, the batchs' job is to restart a Arma 2 OA Game server, and when I run the script manually, the server restarts well, although, when it's being run automatically, the server throws me an error with "No entry Cfg.worlds" and that's an error that something on this line has not been included in the server properly:
start "arma2" /min "C:\Program Files (x86)\Steam\SteamApps\common\Arma 2 CO\Expansion\beta\arma2oaserver.exe" -port=2302 "-config=instance_11_Chernarus\config.cfg" "-cfg=instance_11_Chernarus\basic.cfg" "-profiles=instance_11_Chernarus" -name=instance_11_Chernarus "-mod=#DayZ_Epoch;#DayZ_Epoch_Server;"
The system account which task scheduler uses by default has no access to network resources - so if your server is on a network and you are not using credentials with enough access then that will be the reason.

Resources