From Newsgroup: alt.msdos.batch
On Fri, 14 Jun 2024 09:48:24 +0200, Ammammata wrote:
OS: Windows Server 2008 R2
According to this web sites, https://stackoverflow.com/questions/5085116/windows-2008-server-task-scheduler-does-not-run-bat-batch-job,
there's a bug that prevent a batch file *with quotes inside* to be
executed
the link provides three possible solutions:
1.
create a launcher.bat (without quotes inside) that calls the proper
batch file
2. set the "Starting folder" in the parameters and remove the full path
in the "command"
3.
apply a patch http://support.microsoft.com/kb/951246 but is not
available any more
the task is executed as administrator, both manually (it works) and scheduled (it doesn't)
this is the batch file, that runs correctly when manually executed, as
I wrote above
note the quotes "" in the command for
rem ------------------------ start
D:
cd \TempBackup
@echo off
for /f "tokens=2 delims==" %%i in ('wmic path win32_localtime get
dayofweek /value') do set dow=%%i
xcopy \\192.168.42.54\as400\SV0%dow%\*.* d:\TempBackup\SV /c /f /h /y
/j
rem CURL
rem hidden parameters for privacy
SET FTP_URL=xxx.yyy.zzz.www
SET USERNAME=ftpuser
SET PASSWORD=********
SET REMOTE_DIR=/disk1/CompanyName/%dow%/
SET FOLDER_PATH=d:\TempBackup\SV
REM Iterate over each file in the folder and upload it using curl
FOR %%F IN ( %FOLDER_PATH%\*.* ) DO curl -T %%F ftp://%USERNAME%:%PASSWORD%@%FTP_URL%%REMOTE_DIR% --ftp-create-dirs
echo All files processed.
del /q %FOLDER_PATH%\*.*
rem ------------------------ end
any further help is appreciated
have a nice weekend
You misunderstood the problem. That problem has nothing to do with the
problem in your batch file.
The KB951246 problem lies at the `schtasks.exe` program. Not at the code
within the scheduled batch file itself. And it doesn't matter whether the scheduled program is a batch file or not.
https://mskb.pkisolutions.com/kb/951246
e.g. if the program command line which need to be scheduled is supposed to
be run like below.
"d:\my scripts\test.bat" /z "quoted arg"
The command line for creating the scheduled task using schtasks is supposed
to be like below.
schtasks /create /sc daily /tn test /tr "\"d:\my scripts\test.bat\" /z
\"quoted arg\""
However due to the bug in schtasks, the command line of the scheduled
program of the created scheduled task, ends up like below.
d:\my scripts\test.bat /z "quoted arg
Your problem is an entirely different problem. But since you didn't mention
how exactly, your batch file "doesn't work", I could only point out the code which have the potential of causing the problem - which is the curl's
command line for the `FOR` command. i.e.: (long text warning)
curl -T %%F
ftp://%USERNAME%:%PASSWORD%@%FTP_URL%%REMOTE_DIR% --ftp-create-dirs
Here... if the file/folder enumerated by the `FOR` command contains a space
or special character such as `&`, curl won't be executed as inteaded. To fix it, the `%%F` must be double-quoted. i.e.:
curl -T "%%F"
ftp://%USERNAME%:%PASSWORD%@%FTP_URL%%REMOTE_DIR% --ftp-create-dirs
In Windows, when specifying a file system path, it should always be double-quoted if it's not already double-quoted. Especially if the path is unknown, or may vary, or can be anything.
Another example of the need of double-quoting is when your `FOLDER_PATH` variable contains a space or special character. e.g. if it's:
SET FOLDER_PATH=d:\Temp Backup\SV
Then below code line will not work as expected:
del /q %FOLDER_PATH%\*.*
Because it's expanded as:
del /q d:\Temp Backup\SV\*.*
The folder path must be double-quoted like below.
del /q "d:\Temp Backup\SV\*.*"
Thus the code line in the batch file must be like below.
del /q "%FOLDER_PATH%\*.*"
--- Synchronet 3.21d-Linux NewsLink 1.2