1.

Solve : Bat to test existence of a file on list of computers and copy new file.?

Answer»

Hi All

I would appreciate some HELP with this batch file.

I'm trying to write a bat file to ...

1. Interrogate several computers, listed in a .txt file (currently only contains 3 hosts for test purposes)
2. Check for the instance of a specific file (indicating the installation of a specific application)
3. If the file doesn't exist, comment to that effect.
4. If the file does exist, overwrite it with an amended file (without user response).
5. Send the results of the bat file operations to a separate log file.

The code I'm using is ...

Code: [Select]FOR /F %%a IN (C:\FraserDATA\BATs\LispProblems\ComputerList.txt) do (
IF EXIST "c$\Program Files\AutoCAD Architecture 2010\Support\acad2010doc.lsp" GOTO COPY_FILE
echo File doesn't exist
echo.
echo \\%%a ##################
echo.
) >>C:\FraserDATA\BATs\LispProblems\FileCopied.txt
:COPY_FILE
COPY C:\FraserDATA\BATs\LispProblems\acad2010doc.lsp "\\%%a\c$\Program Files\AutoCAD Architecture 2010\Support\" /y

pause

The only result I'm getting is "File doesn't exist" for each computer entry (one definitely has the requiste folder/file entry).

ANYONES help or GUIDANCE would be very much appreciated.
Quote

Interrogate several computers, listed in a .txt file (currently only contains 3 hosts for test purposes)

We don't do that here.Quote
We don't do that here.

Not sure what is meant by this comment. I am administering a NETWORK of some 400+ computers, some with CAD installed. Several have been infected with a mild worm that has corrupted a .lsp file. I wanted to interrogate each computer, check for the existence of the program and replace the corrupt file.

I thought that this was a forum where I would be able to find some sensible help regarding a few problems I have in in writing a batch file to that effect.

Apologies for my ignorance.
You generate a computer name in the %%a variable but then fail to use it in existence test.

Try it this way:

Code: [Select]IF EXIST "\\%%a\c$\Program Files\AutoCAD Architecture 2010\Support\acad2010doc.lsp" GOTO COPY_FILE

On another level, the logic seems illogical. If the lsp file exists, the logic goes to copy_file, drops into the pause, then exits the code. Try either moving the copy_file logic into the for statement and using a if/else construct, or, use a call instead of a goto, and use goto :eof statements after the for loop and after the the copy statement.

Why the pause statement? The output is redirected to a log file, so you shouldn't need it. Batch file are best run from the COMMAND prompt.



Discussion

No Comment Found