Batch file Master needed

atattoogod

Senior member
Feb 18, 2002
293
0
0
Ill try to make this as short as possible.

im trying to make a batch file that will compare 2 files and write a specific qoute to a text file. i have a visual basic program that points to variuos batch files to load multiple computers at work, and now the boss wants a data integrity check included into the program.

this is what i got so far


NET USE \\VWI1 snafu4u /user:administrator

dir /b /s \\VWI1\C\\graphic_db\VBDB >C:\VCOT_config\VWI1graphic_db.txt

im checking a database on a remote computer, inside the vcot_config folder on my computer i have a text file with the OG data base.txt

ive tried these with no success



::IF c:\vcot_config\VWI1graphic.txt==c:\vcot_config\67_graphic_db.txt type VWI1good > 123.txt

IF c:\vcot_config\VWI1graphic.txt==c:\vcot_config\67_graphic_db.txt goto 1

:1

type VWI1good >> 123.txt

and many others

this batch file would run on 40 computers and write to one txt file with a its computer name and saying database checked out

any help would be appreciated

Kaine
 

ScottMac

Moderator<br>Networking<br>Elite member
Mar 19, 2001
5,471
2
0
I'm not sure of your specific syntax for what you're trying to do, but have you looked at the DOS help file?

Try:
C:\ > if /?

to get the specific syntax for the IF command, for example.

Good Luck

Scott
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Why not just use something like rsync to do the copy? It'll do all of the checksumming during the copy for you. If you really need to check them manually yourself I would suggest looking at either VBScript or perl, either will be a lot better than a cmd batch file.
 

atattoogod

Senior member
Feb 18, 2002
293
0
0
I understand this isnt the best way to do a integrity check using a batch file, but i send these batch files to people in the field, and then explain how to change the file to fit the system they are on. and these people dont know the difference from a PC and a shoe, so explaining how to change a vbs script or perl would be impossible. rsync doesnt work for what im trying to do
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
write it in perl, and have perl call a config file. Then you have a simple config.txt file that you have the user open and you walk them through, should be dead simple. You are trying to work on a car with a monkey wrench and a hammer, get the right tools. Barring that, perhaps a way to simply md5sum the files before/after? (shouldn't be too hard)
 

atattoogod

Senior member
Feb 18, 2002
293
0
0
i guess im not explaining my problem correctly, but thanks nweaver for telling me that i going the long way, i understand that

i understand that using a batch file isnt the best- but that is what I HAVE TO USE
this is for my job and they want it a specific way

guess its back to google to work this out or to read more posts about me doing it the wrong way



 

jlazzaro

Golden Member
May 6, 2004
1,743
0
0
your method is all wrong...if statements are used to compare strings, not files.

your going to need to take advantage of the fc, or file compare command. unfortunately it does not return a value of true of false, so your going to have to do some extra coding...

fc file1.txt file2.txt > difference.txt

if the files are the same, differences.txt will be populated by the string "FC: no differences encountered". just load that file, search for the string, and if its exists they're are the same. if not, they're different.


again, this isnt the best method, and with large files i dont know how well it will perform. To the person insisting on batch files, do they have any technical or programming experience? highly doubt it... theres always a better way to do things, and for them to not take any recommendations on a faster, more functional solution shows their ignorance.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
To the person insisting on batch files, do they have any technical or programming experience? highly doubt it... theres always a better way to do things, and for them to not take any recommendations on a faster, more functional solution shows their ignorance.

They probably assume that's the only way to get it to run on any host without installing additional software, but AFAIK every Windows host has WSH installed by default so VBS would work too.
 

atattoogod

Senior member
Feb 18, 2002
293
0
0
thank you jlazzaro for some good advice, i tried these commands but didnt get the result i needed


fc /b C:\VCOT_config\67_graphic_db.txt C:\VCOT_config\67_graphic_db.txt goto 1

:1
TYPE vwi1_blah blah > whatever.txt


fc /b c:\vcot_config\VWI1graphic.txt==c:\vcot_config\67_graphic_db.txt > C:\VCOT_config\blah.txt

i can get it to say there are no differences, but i need it to list the computer name and i would be good

i understand every ones point on what i am doing, but this is a quick fix to please a big boss that wants to see a button, the program that is used to load computers consists of all batch files with a visual studio face. The system works well for what it is used for
 

jlazzaro

Golden Member
May 6, 2004
1,743
0
0
Originally posted by: atattoogod
i can get it to say there are no differences, but i need it to list the computer name and i would be good
now were gettin to the basics ;)

ECHO Computer name: %COMPUTERNAME% >> C:\VCOT_config\blah.txt

if your interested in more fc switches, reference this
 

SoulAssassin

Diamond Member
Feb 1, 2001
6,135
2
0
Originally posted by: jlazzaro
your method is all wrong...if statements are used to compare strings, not files.

your going to need to take advantage of the fc, or file compare command. unfortunately it does not return a value of true of false, so your going to have to do some extra coding...

fc file1.txt file2.txt > difference.txt

if the files are the same, differences.txt will be populated by the string "FC: no differences encountered". just load that file, search for the string, and if its exists they're are the same. if not, they're different.


again, this isnt the best method, and with large files i dont know how well it will perform. To the person insisting on batch files, do they have any technical or programming experience? highly doubt it... theres always a better way to do things, and for them to not take any recommendations on a faster, more functional solution shows their ignorance.

Close but not quite.

@echo off
fc /L c:\file1.txt c:\file2.txt
if %errorlevel% == 1 echo Files do not match on %computername%! >> \\srvr\shr\output.log



Also, if you have admin rights to all 40 machines and can get a list of them all comma seperated it's real easy to write a script that will grab everything all at once.
 

SoulAssassin

Diamond Member
Feb 1, 2001
6,135
2
0
Contents of script1.cmd

script2.cmd server1,server2,server3,server4,end



contents of script2.cmd

@echo off
:loop
fc.exe /L \\%1\c$\file1.txt \\%1\c$\file2.txt
if %errorlevel% == 1 echo Files do not match on %1! >> \\srvr\shr\output.log
shift
if %1 == end goto :eof
goto :loop
:eof
 

atattoogod

Senior member
Feb 18, 2002
293
0
0
that is what im talking about, thanks soul assassin im trying it now and ill see how it works.


and i do have admin rights to all the machines
 

atattoogod

Senior member
Feb 18, 2002
293
0
0
thanks for the info soul assassin and jlazzaro, it lead me to this

fc /L C:\VCOT_config\software\67_graphic_db.txt C:\VCOT_config\VWI1graphic.txt | FIND "FC: no dif" | echo VWI1 Files match > C:\VCOT_config\1111.txt
fc /L C:\VCOT_config\software\67_graphic_db.txt C:\VCOT_config\VWI1graphic.txt
if %errorlevel% == 1 echo VWI1 Files do not match >> C:\VCOT_config\1111.txt


fc /L C:\VCOT_config\software\67_graphic_db.txt C:\VCOT_config\VWI2graphic.txt | FIND "FC: no dif" | echo VWI2 Files match > C:\VCOT_config\1111.txt
fc /L C:\VCOT_config\software\67_graphic_db.txt C:\VCOT_config\VWI2graphic.txt
if %errorlevel% == 1 echo VWI2 Files do not match >> C:\VCOT_config\1111.txt

fc /L C:\VCOT_config\software\67_graphic_db.txt C:\VCOT_config\VWI3graphic.txt | FIND "FC: no dif" | echo VWI3 Files match > C:\VCOT_config\1111.txt
fc /L C:\VCOT_config\software\67_graphic_db.txt C:\VCOT_config\VWI3graphic.txt
if %errorlevel% == 1 echo VWI3 Files do not match >> C:\VCOT_config\1111.txt


this is just part of the batch, but this is the only thing that im stuck on

i want to write to one file, but this method over writes the text file, how do i get it to add text instead of overwriting

Kaine
 

SoulAssassin

Diamond Member
Feb 1, 2001
6,135
2
0
you're using a mix of >> and >, the single redirection (> ) will overwrite the file, the double (>> ) will append. I usually use a > at the beginning of a script to get a fresh start and everything from there a >> to append. If what you have works for you, run with it, but I think you overcomplicated things. A file match will return an errorlevel of 0 and you can use that to determine if they are the same instead if piping it to the find and then the echo..
 

atattoogod

Senior member
Feb 18, 2002
293
0
0
heres what i got


NET USE \\VWI1 snafu4u /user:administrator

dir /b /s \\VWI1\C\\graphic_db\VBDB >C:\VCOT_config\verify\VWI1graphic.txt

echo VWI1 Files Match > C:\vcot_config\verify\VWI1.txt
fc /L C:\VCOT_config\software\67_graphic_db.txt C:\VCOT_config\verify\VWI1graphic.txt
if %errorlevel% == 1 echo VWI1 Files do not match > C:\VCOT_config\verify\VWI1.txt

::***********************VWI2**********************************************************
NET USE \\VWI2 snafu4u /user:administrator

dir /b /s \\VWI2\C\\graphic_db\VBDB >C:\VCOT_config\verify\VWI2graphic.txt

echo VWI2 Files Match > C:\vcot_config\verify\VWI2.txt
fc /L C:\VCOT_config\software\67_graphic_db.txt C:\VCOT_config\verify\VWI2graphic.txt
if %errorlevel% == 1 echo VWI2 Files do not match > C:\VCOT_config\verify\VWI2.txt

ETC....

TYPE C:\VCOT_config\verify\VWI1.txt > C:\VCOT_config\verify\Graphic_db.txt
TYPE C:\VCOT_config\verify\VWI2.txt >> C:\VCOT_config\verify\Graphic_db.txt

ETC....

START NOTEPAD.EXE C:\VCOT_config\verify\Graphic_db.txt

exit

it seems to work pretty good, ive got to load a system with about 15 computers on friday and ill do more tests then