Created
February 15, 2012 15:31
-
-
Save ChrisMoney/b6ad85155c1ee1f0707f to your computer and use it in GitHub Desktop.
Batch/DOS --Update Anitvirus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Update Anti Virus | |
| Home users just want to update their antivirus. Business users | |
| are usually admins who want to grab the latest update so they can | |
| redistribute it within their company. And they want to know when | |
| a new update is available so they can trigger some other | |
| notification or distribution program. The problem is that the name | |
| of the update changes, so that makes it harder to code for something | |
| when you don't know the name in advance! | |
| Okay. So here's the trick. No scripting or external programs needed. | |
| You can do it all in batch. The batch will control the command-line | |
| FTP program that is part of Windows. You don't NEED know the name. | |
| Instead you just do an FTP DIR (or LS) command to show all sdat files. | |
| And you use the FTP MGET command to grab the files regardless of name. | |
| The FTP sequence is like this: | |
| open ftp.nai.com | |
| anonymous | |
| naiuser@nai.com | |
| dir virusdefs/4.x/sdat* C:\today.txt | |
| bye | |
| Having done that, you'll have a C:\today.txt file with the following | |
| text: | |
| 06-01-04 06:08PM 5518927 sdat4364.exe | |
| Yesterday, you did the same thing. Think...... You can compare | |
| yesterday's file with today's file! If there is no update, the files | |
| will be the same. You use the FC command to compare files: | |
| fc C:\yesterday.txt C:\today.txt | find "no differences encountered" | |
| if errorlevel 1 goto NEWFILE | |
| goto OLDSTUFF | |
| So -- Do I put it all together for you? Let's call the FTP text above | |
| "today.scr". We'll make a separate FTP download script called "sdat.scr" | |
| which will have this: | |
| open ftp.nai.com | |
| anonymous | |
| naiuser@nai.com | |
| cd /virusdefs/4.x | |
| lcd C:\ | |
| binary | |
| hash | |
| prompt | |
| mget sdat*.exe | |
| bye | |
| And the batch file that ties them all together: | |
| copy /y C:\today.txt C:\yesterday.txt | |
| %windir%\system32\ftp.exe -s:C:\today.scr | |
| fc C:\yesterday.txt C:\today.txt | find "no differences encountered" | |
| if not errorlevel 1 goto DONE | |
| C: | |
| cd C:\ | |
| for %%x in (sdat*.exe) do del %%x | |
| %windir%\system32\ftp.exe -s:C:\sdat.scr | |
| :: Insert notification and distribution commands here | |
| NET SEND Administrator There is a Virus Update | |
| for %%x in (sdat*.exe) do copy /y %%x F:\Share\sdat.exe | |
| :DONE | |
| I used the first FOR line to delete the old SDAT file. It's really | |
| just another way of doing a "del sdat*.exe". Doing it with FOR avoids | |
| some problems with "Are you sure" prompts with wildcard deletes, but... | |
| I don't think it's really needed. If "del sdat*.exe" works for you, | |
| you could use it. The second FOR command copies the sdat file over to | |
| your network with a common name. The common name makes it easy for you | |
| to hard-code an update script for your clients. Once again, using FOR | |
| avoids problems with wildcard copies. I'm willing to bet the simpler | |
| "copy sdat*.exe F:\Share\sdat.exe" wouldn't work reliably on all systems, | |
| but you could try it if you don't like the FOR command. You can see I | |
| have an aversion to wildcard "action" commands and prefer to limit wildcards | |
| to generating virtual lists. | |
| I could have written a single larger batch file that created the two needed | |
| FTP scripts as needed, but keeping them separate makes it easier to | |
| understand. Oh -- Be sure to create a dummy empty "today.txt" before you run | |
| the batch file the first time. That way the COPY and FC commands won't be | |
| upset on the first run! | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment