Windows批处理脚本未在Control-M中运行

时间:2017-08-21 08:14:15

标签: windows batch-file control-m

最近我编写了一个Windows批处理脚本,用于从SFTP位置下载文件。为此,我使用了 SSH Tectia软件提供的命令 SCPG3 。手动运行或通过Windows任务计划程序进行计划时,脚本运行正常,没有任何错误。

但是当脚本在 Control-M 中安排时,真正的问题出现了。脚本完全停止执行命令SCPG3。该命令用于连接SFTP位置并下载所需文件。

@echo off

IF "%OS%" == "Windows_NT" setlocal enabledelayedexpansion enableextensions

SET ICS_CURRENT_DIRECTORY=F:/SCBUtility/ICSInterface
set count=0
set nullCount=0
For /F "tokens=1* delims==" %%A IN (%ICS_CURRENT_DIRECTORY%/ICSSymphonyDailyJob.properties) DO (
    IF "%%A"=="SYMPHONY_ZIP_DOWNLOAD_DRIVE" set SYMPHONY_ZIP_DOWNLOAD_DRIVE=%%B
    IF "%%A"=="SYMPHONY_ZIP_DOWNLOAD_LOCATION" set SYMPHONY_ZIP_DOWNLOAD_LOCATION=%%B
    IF "%%A"=="SYMPHONY_DOWNLOAD_SFTP_URL" set SYMPHONY_DOWNLOAD_SFTP_URL=%%B
    IF "%%A"=="SYMPHONY_DOWMLOAD_PATH" set SYMPHONY_DOWMLOAD_PATH=%%B
    IF "%%A"=="SYMPHONY_LOG_FILE" set SYMPHONY_LOG_FILE=%%B
    IF "%%A"=="SYMPHONY_DOWNLOAD_FILE_FORMAT" set SYMPHONY_DOWNLOAD_FILE_FORMAT=%%B
    IF "%%A"=="SYMPHONY_FILE_PATTERN" set SYMPHONY_FILE_PATTERN=%%B
    IF "%%A"=="SYMPHONY_FILES_DOWNLOAD_FREQUENCY" set SYMPHONY_FILES_DOWNLOAD_FREQUENCY=%%B
    IF "%%A"=="SYMPHONY_REKON_FILE" set SYMPHONY_REKON_FILE=%%B
)

Echo %date% %time% -----------------------------Extracting Symphony zip files from SFTP Location---------------------- >> %SYMPHONY_LOG_FILE%

%SYMPHONY_ZIP_DOWNLOAD_DRIVE%:
IF NOT EXIST "%SYMPHONY_ZIP_DOWNLOAD_LOCATION%" MKDIR "%SYMPHONY_ZIP_DOWNLOAD_LOCATION%"
set CURRENT_DIR=%SYMPHONY_ZIP_DOWNLOAD_LOCATION%
cd %CURRENT_DIR%

set x=%SYMPHONY_FILES_DOWNLOAD_FREQUENCY%
set i=-1

for /L %%A in (1,1,%x%) do (
    set /a i=!i!+1
    call:myDateFunc %i%
)

call :fileCounter %SYMPHONY_ZIP_DOWNLOAD_LOCATION%

if %count% NEQ %nullCount% (
    call %ICS_CURRENT_DIRECTORY%/Symphony_Archive.cmd
    call %ICS_CURRENT_DIRECTORY%/Symphony_Temp_Move.cmd
    goto :eof
) ELSE (
    Echo No files available for download.
    Echo  %date% %time% no Symphony files are available for download >> %SYMPHONY_REKON_FILE%
    Echo  %date% %time% no Symphony files are available for download >> %SYMPHONY_LOG_FILE%
    Exit /b %ERRORLEVEL%
)


:fileCounter
echo %SYMPHONY_ZIP_DOWNLOAD_LOCATION%
for %%a in (""%SYMPHONY_ZIP_DOWNLOAD_LOCATION%\*.zip"") do set /a count+=1
Echo no of symphony zip files downloaded:: %count%
Echo %date% %Time%: no of symphony zip files downloaded from SFTP location: %count% >> %SYMPHONY_REKON_FILE%
Echo %date% %Time%: no of symphony zip files downloaded from SFTP location: %count% >> %SYMPHONY_LOG_FILE%
goto :eof


:myDateFunc
for /f %%a in ('"powershell [DateTime]::Now.AddDays(-%i%).ToString('yyyy-MM-dd')"') do (
    ECHO %DATE%  %TIME% : CHECKING FOR ZIPS FOR DATE : %%a >> %SYMPHONY_LOG_FILE%
    scpg3 -p >> %SYMPHONY_LOG_FILE% %SYMPHONY_DOWNLOAD_SFTP_URL%:%SYMPHONY_DOWMLOAD_PATH%%SYMPHONY_FILE_PATTERN%%%a_%SYMPHONY_DOWNLOAD_FILE_FORMAT% %SYMPHONY_ZIP_DOWNLOAD_LOCATION%
    ECHO %DATE%  %TIME% : CONNECTION TO SFTP LOCATION SUCCESSFULL!! >> %SYMPHONY_LOG_FILE%
    ECHO CONNECTION TO SFTP LOCATION SUCCESSFULL!!

    IF %ERRORLEVEL% EQU 0 (
        ECHO %ERRORLEVEL%
        ECHO DOWNLOADING ZIPS FOR THIS DATE : %%a
        ECHO %DATE%  %TIME% : DOWNLOADED ZIPS ON THIS DATE : %%a >> %SYMPHONY_LOG_FILE%
    ) ELSE (
        ECHO %ERRORLEVEL%
        ECHO NO ZIPS AVIALABLE FOR DOWNLOADING ON THIS DATE : %%a
        ECHO %DATE%  %TIME% : NO ZIPS AVIALABLE FOR DOWNLOADING ON THIS DATE : %%a >> %SYMPHONY_LOG_FILE%

    )
)
Exit /b %ERRORLEVEL%

脚本在到达命令行时停止:

scpg3 -p >> %SYMPHONY_LOG_FILE% %SYMPHONY_DOWNLOAD_SFTP_URL%:%SYMPHONY_DOWMLOAD_PATH%%SYMPHONY_FILE_PATTERN%%%a_%SYMPHONY_DOWNLOAD_FILE_FORMAT% %SYMPHONY_ZIP_DOWNLOAD_LOCATION%

即使使用完整文件名为scpg3的此命令行也无法解决问题:

"C:\Program Files (x86)\SSH Communications Security\SSH Tectia\SSH Tectia Client\scpg3.exe" -p >> %SYMPHONY_LOG_FILE% %SYMPHONY_DOWNLOAD_SFTP_URL%:%SYMPHONY_DOWMLOAD_PATH%%SYMPHONY_FILE_PATTERN%%%a_%SYMPHONY_DOWNLOAD_FILE_FORMAT% %SYMPHONY_ZIP_DOWNLOAD_LOCATION%

我已提供所有必需的安全权限。

有人可以帮我解决这个问题吗?

0 个答案:

没有答案