[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] [已解决]自动下载symantec最新病毒库的批处理求优化

本帖最后由 lijinan 于 2015-11-27 17:16 编辑

在论坛的帮助下,写了个批处理,自动下载symantec最新病毒库的;感觉还可以优化,请大侠支招.
第一版:
  1. @echo off
  2. color
  3. cd /d "%~dp0"
  4. echo job start at %date:~0,10% %time:~0,8%>>log.txt
  5. if exist md5-hash.txt del /f /a /q md5-hash.txt
  6. aria2c -c -s10 -x10 -j1 -V --check-certificate=false --file-allocation=none https://www.symantec.com/avcenter/download/md5-hash.txt
  7. for /f "tokens=2 delims= " %%a in ('findstr "20.*-v5i64.exe" "md5-hash.txt"') do set filename1=%%a
  8. for /f "tokens=2 delims=/" %%a in ('findstr "20.*-SONAR_IU_SEP.exe" "md5-hash.txt"') do set filename2=%%a
  9. for /f "tokens=2 delims=/" %%a in ('findstr "20.*-IPS_IU_SEP.exe" "md5-hash.txt"') do set filename3=%%a
  10. if exist %filename1% rename %filename1% %filename1%.bak
  11. if exist %filename2% rename %filename2% %filename2%.bak
  12. if exist %filename3% rename %filename3% %filename3%.bak
  13. if exist *.exe del /f /a /q *.exe
  14. if exist FileChk.txt del /f /a /q FileChk.txt
  15. if exist %filename1%.bak rename %filename1%.bak %filename1%
  16. if exist %filename2%.bak rename %filename2%.bak %filename2%
  17. if exist %filename3%.bak rename %filename3%.bak %filename3%
  18. if not exist %filename1% aria2c -c -s10 -x10 -j1 -V --check-certificate=false --file-allocation=none http://definitions.symantec.com/defs/%filename1%
  19. if not exist %filename2% aria2c -c -s10 -x10 -j1 -V --check-certificate=false --file-allocation=none http://definitions.symantec.com/defs/sonar/%filename2%
  20. if not exist %filename3% aria2c -c -s10 -x10 -j1 -V --check-certificate=false --file-allocation=none http://definitions.symantec.com/defs/ips/%filename3%
  21. fsum -md5 -sha1 *.exe md5-hash.txt>FileChk.txt
  22. echo job end at %date:~0,10% %time:~0,8%>>log.txt
  23. goto end
  24. :: 结束程序
  25. :end
  26. echo.
  27. echo 任意键退出!
  28. pause >nul 2>nul
  29. goto :Eof
复制代码
第二版:
  1. @echo off
  2. color
  3. cd /d "%~dp0"
  4. echo job start at %date:~0,10% %time:~0,8%>>log.txt
  5. if exist md5-hash.txt del /f /a /q md5-hash.txt
  6. :redownload
  7. aria2c -c -s10 -x10 -j1 -V --check-certificate=false --file-allocation=none https://www.symantec.com/avcenter/download/md5-hash.txt >nul 2>nul
  8. if not exist md5-hash.txt goto redownload
  9. :: Create Filename
  10. for /f "tokens=2 delims= " %%a in ('findstr "2.......-...-v5i64.exe" "md5-hash.txt"') do set filename1=%%a
  11. for /f "tokens=2 delims=/" %%a in ('findstr "2.......-...-SONAR_IU_SEP.exe" "md5-hash.txt"') do set filename2=%%a
  12. for /f "tokens=2 delims=/" %%a in ('findstr "2.......-...-IPS_IU_SEP.exe" "md5-hash.txt"') do set filename3=%%a
  13. if exist dl.txt del /f /a /q dl.txt
  14. echo http://definitions.symantec.com/defs/%filename1%>dl.txt
  15. echo http://definitions.symantec.com/defs/sonar/%filename2%>>dl.txt
  16. echo http://definitions.symantec.com/defs/ips/%filename3%>>dl.txt
  17. if exist %filename1% rename %filename1% %filename1%.bak
  18. if exist %filename2% rename %filename2% %filename2%.bak
  19. if exist %filename3% rename %filename3% %filename3%.bak
  20. if exist *.exe del /f /a /q *.exe
  21. if exist %filename1%.bak rename %filename1%.bak %filename1%
  22. if exist %filename2%.bak rename %filename2%.bak %filename2%
  23. if exist %filename3%.bak rename %filename3%.bak %filename3%
  24. :: Create FileChk.txt
  25. if exist FileChk.txt del /f /a /q FileChk.txt
  26. for /f "tokens=1-2 delims= " %%a in ('findstr "2.......-...-v5i64.exe" "md5-hash.txt"') do set chk1=%%a *%%b
  27. for /f "tokens=1-3 delims=/ " %%a in ('findstr "2.......-...-SONAR_IU_SEP.exe" "md5-hash.txt"') do set chk2=%%a *%%c
  28. for /f "tokens=1-3 delims=/ " %%a in ('findstr "2.......-...-IPS_IU_SEP.exe" "md5-hash.txt"') do set chk3=%%a *%%c
  29. echo %chk1%>FileChk.txt
  30. echo %chk2%>>FileChk.txt
  31. echo %chk3%>>FileChk.txt
  32. fsum -c FileChk.txt >nul 2>nul
  33. if %errorlevel% EQU 0 goto end
  34. :filedownload
  35. if exist *.exe del /f /a /q *.exe
  36. if exist *.aria2 del /f /a /q *.aria2
  37. aria2c -c -s10 -x10 -j1 -V --check-certificate=false --file-allocation=none -idl.txt >nul 2>nul
  38. fsum -c FileChk.txt >nul 2>nul
  39. if %errorlevel% EQU 0 goto end
  40. if not %errorlevel% EQU 0 goto filedownload
  41. goto end
  42. :: 结束程序
  43. :end
  44. fsum -md5 -sha1 *.exe md5-hash.txt dl.txt>>FileChk.txt
  45. echo job end at %date:~0,10% %time:~0,8%>>log.txt
  46. echo.
  47. echo 任意键退出!
  48. pause >nul 2>nul
  49. goto :Eof
复制代码

没感觉还能有什么优化, 用形如 for %%a in (1 2 3) do... 来整合简短一下是可以的

原始的也就二三十行, 简短也没多大意义,  最重要的是能正常运行就好了

TOP

直接覆盖写文件不就好了嘛,不用写这么多判断文件存不存在。
下载安装python3 https://www.python.org/downloads/ 代码存为xx.py 双击运行或IDLE打开F5运行

TOP

回复 3# 依山居


    有时候下载会出错或者停止,校验后继续下载,可保证下载的东西是OK的。

TOP

返回列表