• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Part IX: Appendices > VIRUPDATE.BAT

VIRUPDATE.BAT

A common task many administrators face is to update one or more files on all their servers. Although tools such as SMS exist to meet this need, not many environments have this kind of tool available. Therefore, you may find this tool very interesting. As an example, this batch file updates a hypothetical antivirus scanner with a new data file to enable protection against the newest viruses. It is shown in Code Listing C.2.

Code Listing C.2. The VIRUPDATE.BAT Script

01 @ECHO OFF
02 SET SUCCESS=0
03 SET FAIL=0
04
05 SET PROGNAME=%~n0
06
07 CALL :LOGIT Beginning operation…
08 ECHO.
09
10 FOR /F "eol=;" %%I IN (SERVERS.TXT) DO CALL :DOIT %%I
11
12 ECHO.
13 CALL :LOGIT Operation completed.
14 CALL :LOGIT Successes: %SUCCESS%
15 CALL :LOGIT Failures: %FAIL%
16 ECHO.
17
18 GOTO :EOF
19
20 :DOIT
21 CALL :LOGIT Updating server %1…
22 IF NOT EXIST \\%1\ADMIN$ GOTO SRVDOWN
23 CALL :LOGIT Stopping AntiVirus Service on %1…
24 SC \\%1 STOP VIRUSSVC
25 CALL :LOGIT Updating virus definitions on %1…
26 IF EXIST \\%1\VIRUSUPDATE\VIRUS.OLD DEL \\%1\VIRUSUPDATE\VIRUS.OLD
27 IF EXIST \\%1\VIRUSUPDATE\VIRUS.DAT REN \\%1\vIRUSUPdATE\VIRUS.DAT VIRUS.OLD
28 COPY NEWVIRUS.DAT \\%1\VIRUSUPDATE
29 IF NOT EXIST \\%1\VIRUSUPDATE\VIRUS.DAT GOTO COPYPROB
30 SC \\%1 START VIRUSSVC
31 CALL :LOGIT Server %1 completed.
32 ECHO.
33 SET /A SUCCESS=%SUCCESS% + 1
34 GOTO :EOF
35
36 :SRVDOWN
37 CALL :LOGIT ERROR! Server %1 unreachable.
38 SET /A FAIL=%FAIL% + 1
39 GOTO :EOF
40
41 :COPYPROB
42 CALL :LOGIT ERROR! Problem during file copy to %1.
43 SET /A FAIL=%FAIL% + 1
44 GOTO :EOF
45
46 :LOGIT
47 ECHO %*
48 ECHO %* >>%PROGNAME%.LOG
49 GOTO :EOF


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint