Announcement

Collapse
No announcement yet.

Need help with an incremental seach and copy script (bat)

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help with an incremental seach and copy script (bat)

    hi all,
    I need to write a script that does the following:

    1. search Log files on 40 different servers (same credentials)
    * only log files that have changed in the last 24 hours.
    2. copy them to a temp folder
    3. add them to archive

    The first step is the problematic one for me..
    In linux it's done with pipe lines and greps...

    10x in advance
    Or.
    Best regards,
    Or.

  • #2
    Re: Need help with an incremental seach and copy script (bat)

    I would really appreciate it if someone can help...
    Best regards,
    Or.

    Comment


    • #3
      Re: Need help with an incremental seach and copy script (bat)

      You want to automate steps by using a script, you should give more information and details to write the script.
      If you seach for all logfiles on a computer, you might also find logfiles in different formats (not all have to be just basic-ASCII text files). Searching 40 computer can take a while. And what is exactly your goal to only search for log-files that have been modified in the last 24 hours? - how often do you want to run this script?

      1. search Log files on 40 different servers (same credentials)
        * only log files that have changed in the last 24 hours.
      2. copy them to a temp folder
      <..>
      The first step is the problematic one for me..
      To search with a batch for files by 'last-date-modified', you can use Forfiles.exe. (note: Comparing date-strings in a batch can give some problems because of different date formats in different OS languages)

      Here is an example how to find files on a remote computer that have been changed just 'today':
      Code:
      ::This batch search for *.log files on the C-drive\folder and subfolders
      ::on several remote computers
      ::
      :: It performs the steps below in a loop - for every computer on the list;
      :: 1. It reads the next computername from a text file
      :: 2. create a temporary drive mapping using the administrative share on the remote computer
      ::   (required for the use of the 'Forfiles' command, because an unc-path cannot set as the active path)
      :: 3. With Forfiles a SourceDir on the remote computer will 
      ::    be scanned for *.log files that have been modified *Today*
      :: 4. Forfiles is instructed to copy the matching files to a DestinationFolder
      ::
      :: - Rems 2008 - 
      :: http://forums.petri.com/showthread.php?t=22646
      
      @echo off
      SetLocal enableextensions
      
      Set "ListOfServerNames=c:\My servers.txt"
      Set "DestinationFolder=C:\copiedfiles"
      
      Set "SourceDir=c:\test" =Directory on the target computers to be scanned
      
      Set "strCommand=xCopy /Y /V /C /Q /D /I @path \"%DestinationFolder%\%%*\\""
      
      For /f "tokens=2* delims= " %%i in ('echo.^|date/t') do set Today=%%i
      (Set SourceDir=%SourceDir::=$%)
      For /f "usebackq" %%* in ("%ListOfServerNames%") do (
        PushD "\\%%*\%SourceDir%" &&(
        Forfiles.exe /s /p "." /m "*.log" /d +%Today% /c "cmd.exe /c If @isdir==FALSE %strCommand%" 2>nul
        )
        PopD
      )
      
      :: Done copying
      
      ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      :: Merge all the copied logfiles to one txt-file in the 
      :: destination folder. 
      :: Then delete the *.log files from the folder (optional).
      ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      For /f "usebackq" %%* in ("%ListOfServerNames%") do (
        If Exist "%DestinationFolder%\%%*" (
        PushD "%DestinationFolder%\%%*"
        Copy/b "*.log" ..\"%%*-merged-logs.txt" &&Del *.log /q
        PopD
       )
      )
      
      :end
      test this shell script first!

      \Rems
      Last edited by Rems; 29th March 2008, 21:31. Reason: added the line "If Exist..."

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: Need help with an incremental seach and copy script (bat)

        10x a lot Rems!!
        Best regards,
        Or.

        Comment

        Working...
        X