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.
Related
I have a below batch script:
#echo off
cd C:\Program Files (x86)\Project
CALL init_env.bat
cd C:\Users\Documents\Project\Release
START app.exe -ver 133
echo application has been stopped
This starts the app.exe. On the terminal it also says application has been stopped. Is there any way I can pause the script after executing the line START app.exe -ver 133 and only run echo application has been stopped when the app was closed or crashed for some reason.
Thanks
The command START should be removed because it starts the executable app.exe as separate process being executed parallel to cmd.exe processing the batch file. Then cmd.exe processing the batch file starts app.exe and waits with further processing of the batch file until app.exe terminated itself.
It is also recommended to always enclose a file/folder string in " even on not really being necessary. So cd /D "C:\Program Files (x86)\Project" and call "init_env.bat" should beĀ used or even better call "C:\Program Files (x86)\Project\init_env.bat" if that works also because of batch file init_env.bat is written to work independent on what is the current directory on execution. And last cd /D "C:\Users\Documents\Project\Release" and "app.exe" -ver 133 should be written in the batch file.
Run in a command prompt window cd /? for help on command CD and meaning of option /D.
start /? outputs the help for command START in cmd window.
#echo off
call "C:\Program Files (x86)\Project\init_env.bat"
cd /D "C:\Users\Documents\Project\Release"
"app.exe" -ver 133
echo application has been stopped
See also the predefined Windows environment variables.
I made a script to launch mysql from a batch file, but once the option to start the server is picked, the batch file is prevented from continuing due to executing the file.
How do I make it continue once the command is executed?
The section of code
:START
cd "C:\Program Files\MySQL\MySQL Server 5.6\bin"
CALL "mysqld" -u y121 -P 3307 &
cls
PAUSE
I am trying to make a batch file that will check certain SVN repositories for updates each morning. I want to store local repository names in a file (SVN_check_list.txt) and have the console show me the list. My code, posted below, works when I just run the batch file:
#echo off
echo Checking for updates...& echo.
for /F %%A in (SVN_check_list.txt) do (
echo Checking '%%A'
svn status %%A -u )
pause
However, when I try to run it through Windows Task Scheduler (while I am logged in), it runs the code but does not display anything until the 'pause' at the end. When I turn echo on, it shows the commands (svn status -u) but not the output. How can I make this batch file display the outputs of the svn status command even when I run it with task scheduler?
Try passing cmd as the Program/Script to run in Scheduler with arguments /k "C:\My Batch File Folder\MyScript.bat"
This will launch the console.
I found this solution that seems to work: Run a batch file with Windows task scheduler
Basically:
Action: Start a program
Program/script: cmd
Add arguments: /k "C:\Users\tanderson\Documents\setup.bat"
Start in: C:\Users\tanderson\Documents (No quotes)
I've created a batch file to copy files from my machine to a backup machine. The batch file is this:
#echo off
cd D:\Backup
echo %date% %time% - Starting backup process. >> D:\Backup\backup_log.txt
xcopy D:\T\Source I:\AREA\USER\Backup\T\Source /s/d/y/c/v/r/i/e >> D:\Backup\backup_log.txt
echo %date% %time% - Stopping backup process. >> D:\Backup\backup_log.txt
exit
When running this bat file as command line, it copies all the new files and folders from source folder to a destination folder. Makes an update of the Source folder in I:\AREA\USER\Backup\T\Source. This is what I want.
D:\Backup>Backup.bat
But when I configure the same bat execution using Windows Task Scheduler, the scheduler runs without any errors but doesn't copy/update the new files.
I'm using Windows 7. I've made some tests and with this scenario, I can't see where the problem is. Maybe some configuration on Task Scheduler. I've read the information of the xcopy parameters. But with these parameters work in command line, why it doesn't work using windows scheduler?
Any help?
Thanks!
Filipe
Edit1: I've found something that can help to parse the error. If, in the Task Scheduler, I select the option Run only when user is logged on, it works. But when I select the other option Run whether user is logged on or not, it doesn't work.
Well... I resolve my problem with this.
The bat file is:
#echo off
cd D:\Backup
echo %date% %time% - Starting backup process. >> D:\Backup\backup_log.txt
xcopy "D:\T\Source" "I:\AREA\USER\Backup\T\Source" /D /E /C /R /H /I /K /Y /V >> D:\Backup\backup_log.txt
echo %date% %time% - Stopping backup process. >> D:\Backup\backup_log.txt
exit
In the Task Scheduler, I've changed the General tab and check "Run only when user is logged on".
I don't know, but in my understanding, the "Run whether user is logged on or not" should work when the user is logged.
I had a similar issue running bat file with XCOPY via Task Scheduler with "Run whether user is logged on or not" set. The ussue was that I have a network location \\domain mapped as disc D: thus my cmd was like
XCOPY /d /y \\192.168.1.1\Data D:\Data
It was running fine just by executing bat file, but task runner didn't copy anything. I've changed it to
XCOPY /d /y \\192.168.1.1\Data \\domain\Data
And everything was fine since then.
I have a batch file which creates backup of SQL DB, makes a zip file and then copies to a mapped network share.
When this batch file is executed from command prompt or RUN window it works perfectly fine. However, when the batch file is called by Windows Task Scheduler it fails to copy file to mapped network share with the error #4.
The run account used in Task Scheduler is same as I am using for Command Prompt. Both the machines are on workgroup with the same user name and password, so sharing permission does not seem to be an issue.
The code is:
set ZipFileName=C:\Temp\ST_%date:~10%%date:~4,2%%date:~7,2%%time:~0,2%%time:~3,2%.zip
C:\Windows\System32\xcopy %ZipFileName% "Z:\WinDB\" /Z /V
IF %ERRORLEVEL% NEQ 0 GOTO error_hndlr
------
:error_hndlr
echo Failed with error #%errorlevel%
exit /B