用于验证它的批处理脚本是该月的第二个星期二,然后确定文件大小

时间:2018-04-17 18:41:06

标签: batch-file

所以我正在编写一个将通过KACE设备部署的脚本,以便为我们的机器安装dell更新。我有更新部分,它将工作,但当我尝试输入逻辑,以确定它是否是该月的第二个星期二,以便应用硬件更新和逻辑,以确定日志文件是否大于45 KB以确定是否安装了任何内容并重新启动系统。

当我将所有内容组合在一起时,我最终得到的错误是(出乎意料。我在整个代码中查看过,而且我没有看到问题的来源。有人可以告诉我我在哪里搞砸了我的代码,所以我能够把它运行起来并投入生产?

@echo off
:: Formatting Date and Time
for /f "tokens=1-4 delims=/ " %%d in ('echo %date%') do (
set dow=%%d
set month=%%e
set day=%%f
set year=%%g
)

pause
:: Picking the 2nd Tuesday
if "%dow%"=="Tue" (
if %day% geq 8 if %day% leq 14 (
    cd %windir%\Sysnative
    manage-bde.exe -protectors -disable c:
    cd "%PROGRAMFILES(X86)%\Dell\CommandUpdate\"
    dcu-cli.exe -policy \\server\dell_updates\Policy.xml -log C:\Temp\%COMPUTERNAME%
    pause
    net use O: \\server\Logs$
    cd O:
    mkdir O:\%COMPUTERNAME%
    del O:\%COMPUTERNAME%\*.xml /s /q
    copy C:\Temp\%COMPUTERNAME%\*.* O:\%COMPUTERNAME%
    setlocal
    set maxbytesize=40000
    set file="C:\Temp\%COMPUTERNAME%\ActivityLog.xml"
    FOR /F "usebackq" %%A IN ('%file%') DO set size=%%~zA

    if %size% LSS %maxbytesize% (
        rmdir c:\temp\%COMPUTERNAME% /s /q
        net use o: /delete
        endlocal
        goto end
        )
        ELSE (
        rmdir c:\temp\%COMPUTERNAME% /s /q
        net use o: /delete
        cd %windir%\Sysnative
        msg.exe * /w /time:0 "Do not press the OK button until you have closed all of your open programs and saved your work.  Pressing OK WILL reboot your computer."
        c:\windows\system32\shutdown.exe -r -f
        endlocal
        goto end
        )
    )
)
:: add the command lines that you want to run on any other day than the 2nd and 4th Monday
pause
:end

0 个答案:

没有答案