标题: [文本处理] [已解决]自动下载symantec最新病毒库的批处理求优化 [打印本页]
作者: lijinan 时间: 2015-11-27 10:58 标题: [已解决]自动下载symantec最新病毒库的批处理求优化
本帖最后由 lijinan 于 2015-11-27 17:16 编辑
在论坛的帮助下,写了个批处理,自动下载symantec最新病毒库的;感觉还可以优化,请大侠支招.
第一版:- @echo off
- color
- cd /d "%~dp0"
- echo job start at %date:~0,10% %time:~0,8%>>log.txt
- if exist md5-hash.txt del /f /a /q md5-hash.txt
- aria2c -c -s10 -x10 -j1 -V --check-certificate=false --file-allocation=none https://www.symantec.com/avcenter/download/md5-hash.txt
- for /f "tokens=2 delims= " %%a in ('findstr "20.*-v5i64.exe" "md5-hash.txt"') do set filename1=%%a
- for /f "tokens=2 delims=/" %%a in ('findstr "20.*-SONAR_IU_SEP.exe" "md5-hash.txt"') do set filename2=%%a
- for /f "tokens=2 delims=/" %%a in ('findstr "20.*-IPS_IU_SEP.exe" "md5-hash.txt"') do set filename3=%%a
- if exist %filename1% rename %filename1% %filename1%.bak
- if exist %filename2% rename %filename2% %filename2%.bak
- if exist %filename3% rename %filename3% %filename3%.bak
- if exist *.exe del /f /a /q *.exe
- if exist FileChk.txt del /f /a /q FileChk.txt
- if exist %filename1%.bak rename %filename1%.bak %filename1%
- if exist %filename2%.bak rename %filename2%.bak %filename2%
- if exist %filename3%.bak rename %filename3%.bak %filename3%
- if not exist %filename1% aria2c -c -s10 -x10 -j1 -V --check-certificate=false --file-allocation=none http://definitions.symantec.com/defs/%filename1%
- if not exist %filename2% aria2c -c -s10 -x10 -j1 -V --check-certificate=false --file-allocation=none http://definitions.symantec.com/defs/sonar/%filename2%
- if not exist %filename3% aria2c -c -s10 -x10 -j1 -V --check-certificate=false --file-allocation=none http://definitions.symantec.com/defs/ips/%filename3%
- fsum -md5 -sha1 *.exe md5-hash.txt>FileChk.txt
- echo job end at %date:~0,10% %time:~0,8%>>log.txt
- goto end
- :: 结束程序
- :end
- echo.
- echo 任意键退出!
- pause >nul 2>nul
- goto :Eof
复制代码
第二版:- @echo off
- color
- cd /d "%~dp0"
- echo job start at %date:~0,10% %time:~0,8%>>log.txt
- if exist md5-hash.txt del /f /a /q md5-hash.txt
- :redownload
- aria2c -c -s10 -x10 -j1 -V --check-certificate=false --file-allocation=none https://www.symantec.com/avcenter/download/md5-hash.txt >nul 2>nul
- if not exist md5-hash.txt goto redownload
- :: Create Filename
- for /f "tokens=2 delims= " %%a in ('findstr "2.......-...-v5i64.exe" "md5-hash.txt"') do set filename1=%%a
- for /f "tokens=2 delims=/" %%a in ('findstr "2.......-...-SONAR_IU_SEP.exe" "md5-hash.txt"') do set filename2=%%a
- for /f "tokens=2 delims=/" %%a in ('findstr "2.......-...-IPS_IU_SEP.exe" "md5-hash.txt"') do set filename3=%%a
- if exist dl.txt del /f /a /q dl.txt
- echo http://definitions.symantec.com/defs/%filename1%>dl.txt
- echo http://definitions.symantec.com/defs/sonar/%filename2%>>dl.txt
- echo http://definitions.symantec.com/defs/ips/%filename3%>>dl.txt
- if exist %filename1% rename %filename1% %filename1%.bak
- if exist %filename2% rename %filename2% %filename2%.bak
- if exist %filename3% rename %filename3% %filename3%.bak
- if exist *.exe del /f /a /q *.exe
- if exist %filename1%.bak rename %filename1%.bak %filename1%
- if exist %filename2%.bak rename %filename2%.bak %filename2%
- if exist %filename3%.bak rename %filename3%.bak %filename3%
- :: Create FileChk.txt
- if exist FileChk.txt del /f /a /q FileChk.txt
- for /f "tokens=1-2 delims= " %%a in ('findstr "2.......-...-v5i64.exe" "md5-hash.txt"') do set chk1=%%a *%%b
- for /f "tokens=1-3 delims=/ " %%a in ('findstr "2.......-...-SONAR_IU_SEP.exe" "md5-hash.txt"') do set chk2=%%a *%%c
- for /f "tokens=1-3 delims=/ " %%a in ('findstr "2.......-...-IPS_IU_SEP.exe" "md5-hash.txt"') do set chk3=%%a *%%c
- echo %chk1%>FileChk.txt
- echo %chk2%>>FileChk.txt
- echo %chk3%>>FileChk.txt
- fsum -c FileChk.txt >nul 2>nul
- if %errorlevel% EQU 0 goto end
- :filedownload
- if exist *.exe del /f /a /q *.exe
- if exist *.aria2 del /f /a /q *.aria2
- aria2c -c -s10 -x10 -j1 -V --check-certificate=false --file-allocation=none -idl.txt >nul 2>nul
- fsum -c FileChk.txt >nul 2>nul
- if %errorlevel% EQU 0 goto end
- if not %errorlevel% EQU 0 goto filedownload
- goto end
- :: 结束程序
- :end
- fsum -md5 -sha1 *.exe md5-hash.txt dl.txt>>FileChk.txt
- echo job end at %date:~0,10% %time:~0,8%>>log.txt
- echo.
- echo 任意键退出!
- pause >nul 2>nul
- goto :Eof
复制代码
作者: aa77dd@163.com 时间: 2015-11-27 13:31
没感觉还能有什么优化, 用形如 for %%a in (1 2 3) do... 来整合简短一下是可以的
原始的也就二三十行, 简短也没多大意义, 最重要的是能正常运行就好了
作者: 依山居 时间: 2015-11-27 17:20
直接覆盖写文件不就好了嘛,不用写这么多判断文件存不存在。
作者: lijinan 时间: 2015-11-27 21:06
回复 3# 依山居
有时候下载会出错或者停止,校验后继续下载,可保证下载的东西是OK的。
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |