Trying to Use beyond Compare to notes differences in a file on about 380 servers.  Can someone help me script this to an output file.

Posted on 2006-06-01
Last Modified: 2012-05-05
I am trying to compare a file on about 300 servers.  I just need to note the size and date of the file on each server to a particular baseline file on my workstation.  Does anyone know of a way to script this using beyond compare and piping the information (only the size and date of the file and maybe the crc) to an output file?  I'm needed to know if there is any difference's, but not necessary what those differences are.  If the file is different , we are planning a rollout of the baseline file to all servers that do not have the file installed.  This is an extremely urgent issue and any help would be greatly appreciated.  Sorry, but I am not the greatest at scripting so please be as specific as possible.
Question by:mdnplace
    LVL 24

    Accepted Solution

    I suggest using a Digest Hash value for you files. You then just have to check against this value and see whether the files are equal.

    So you could use e.g md5sum or write one md5 hash code yourself.
    Probably you better go with sha-1.

    Of course stating the file and collecting that information might work, but if you have some server installed later and copied the file on it then what does teh date of the file gives you.

    Another approach if you just want to be sure that a certain files exist is using rsync from the Master to the Slaves either as in push or pull direction. You could e.g write a file


    then you run
    for all_servers in my_server_list
       rsync -e ssh -avz < files_to_copy  user@remotehost

    or the like



    Author Comment

    Thanks for the quick response.  Right now I do not wish to sync any files only note the servers with a different file than my base line.
    Would the code you sent work with beyond compare?  I was thinking I would need a script that I could run using beyond compare.  This file should be located in the same path on all servers.  My only variable would be the different server name.


    How would I use a simple text file with all my servernames in it and run the size and crc compare using beyond compare on all servers?
    I deal more with networks than programming so forgive me if I ask alot a questions.
    LVL 24

    Expert Comment

    Sorry I had not seen oder understand the beyond compare question. I was reading you're looking for way mirroring files, which can be done with rsync quite nicely. I suggest you visit
    and read a view questions there.

    And yes you're right you have to write a script in beyond compare scripting language.

    I'm sorry having wasted your time.


    Author Comment

    You haven't wasted my time.  When we go to sync these files the above script might come in handy.  Thanks.
    LVL 16

    Expert Comment

    Hi mdnplace,

    I've done this kind of thing many times. I work in EPOS and checking software versions on every till across hundreds of stores is a common requirement.

    In the end I wrote a tool to help out. I've since released it on shareware. Its a Win32 app. If you'd like to try it let me know.

    It doesn't use 'beyond compare' but it can produce SHA1 or CRC32 details along with date,time,file size etc.

    LVL 20

    Assisted Solution

    Here is a script that uses FC and PING to compare a "base" file with the same filename to a list of other locations.  It only determines if the binary content is the same or different... this implies that file size must be identical but not the timestamp.

    Perhaps it will be useful to you.


    ' This script reads a text file containing share names in the format of
    '     server\share\path\
    ' and examines each of those shares for the presence of a file.  If found
    ' the file is them compared to a "base" copy to determine if it is different.
    ' Exceptions are echoed to the console (which can be redirected to a file for further analysis).
    ' Executes "FC /b" to do a binary comparison of two files...
    ' Invoke this script like this:  cscript compare.vbs >exception.txt
    '                            or  cscript compare.vbs >exception.txt > results.txt  
    ' Note:  If some of the servers are "unavailable" this script will run slowly and
    '        appear to "hang up".  It's just the network waiting to timeout before
    '        moving on.  This problem can be mitigated somewhat by adding a "ping"
    '        command just before the FC command to determine if the server is responding
    '        first.

    Option Explicit

    Const ForReading = 1

    Dim ServersLst     '-- name of file containing list of shares to examine.
    Dim FileName       '-- name of file to be compared on all specified shares.
    Dim BaseLocn       '-- name of "base" location that will be compared with all others.
    Dim ReturnCode
    Dim Command
    Dim oFSO
    Dim oWSH
    Dim oFile
    Dim oExec
    Dim sPath

       '-- Change these next 3 values to match your environment...
       FileName   = "SomeFile.txt"
       BaseLocn   = "\\phobos\e$\ee\"
       ServersLst = "E:\EE\Servers.lst"

       Set oFSO = CreateObject("Scripting.FileSystemObject")

       If Not oFSO.FileExists(BaseLocn & FileName) Then
          Wscript.Echo "Base file not found."
       End If

       If Not oFSO.FileExists(ServersLst) Then
          Wscript.Echo "File containing list of servers not found."
       End If

       Set oFile = oFSO.OpenTextFile(ServersLst, ForReading)
       Set oWSH = CreateObject("Wscript.Shell")

       Do Until oFile.AtEndOfStream
          sPath = Trim(oFile.ReadLine)
          If sPath <> "" Then
             If Left(sPath,1) <> "\" Then
                sPath = "\" & sPath
             End If
             If Left(sPath,2) <> "\\" Then
                sPath = "\" & sPath
             End If
             If Right(sPath,1) <> "\" Then
                sPath = sPath & "\"
             End If
             Call CompareFiles(sPath)
          End If

       Set oFile = Nothing
       Set oFSO = Nothing
       Set oWSH = Nothing
       Set oExec = Nothing

    Sub CompareFiles(sPath)

       If Not Ping(sPath) Then
          Wscript.Echo "Unavail " & sPath
          Exit Sub
       End If

       If Not oFSO.FileExists(sPath & FileName) Then
          Wscript.Echo "Missing " & sPath
          Exit Sub
       End If

       Command = "FC /b " & _
                 chr(34) & BaseLocn & FileName & chr(34) & " " & _
                 chr(34) & sPath    & FileName & chr(34) & " >nul"

       ' do the comparison...
       ReturnCode = oWSH.Run(Command, 0, True)

       if ReturnCode = 0 Then
    '''   Wscript.Echo "Same    " & sPath     '' commented so only exceptions are displayed
          Wscript.Echo "Diff    " & sPath
       end if

    End Sub

    Function Ping(sComp)
    Dim sCommand
    Dim sOutput
    Dim sServer
    Dim n

       sServer = sComp
       If left(sServer,2) = "\\" Then
          sServer = Mid(sServer,3)
       End If

       n = InStr(sServer, "\")
       If n > 0 Then
          sServer = left(sServer,n-1)
       End If

       sCommand = "%comspec% /c for /f %q in ('ping -n 1 -w 500 "
       sCommand = sCommand & sServer
       sCommand = sCommand & " ^| find /i ""reply""') do (echo 1)"
       Set oExec = oWSH.Exec(sCommand)

       sOutput = sOutput & oExec.StdOut.ReadAll

       Ping = Len(sOutput) > 0

    End Function

    Author Comment

    That looks like it will definately work.  I will try that monday to compare my files.  Thanks for your help.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
    If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now