Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append text file data to log file, .bat

Tags:

batch-file

This .bat file is used for website replication, transferring files from development to production and then produces a log file with job statistics. I'd like to include the contents of a text file at the end of the log file. Is there an easy way to do this?

@ECHO off
    IF "%1"=="" goto :Syntax
    for %%d in (%1) do call :sub0 %%d
    goto :END

    :sub0
    Echo Replicating Site %1
    rem subinacl /subdirectories D:\inetpub\%1\*.* /setowner=Administrators REM /grant=Administrators=f /grant=SYSTEM=f
    robocopy D:\inetpub\%1 \\111.111.11.11\D$\inetpub\%1 /MIR /ZB /NP /R:3 /W:3 /XD SiteReplication /XD SiteLogs /XD Administration /XD sitestatistics /XF calendar_secure.asp /XF navigation_editor.asp  /LOG:logs\test%USERNAME%.log
    robocopy D:\inetpub\%1 \\111.111.11.11\D$\inetpub\%1 /MIR /ZB /NP /R:3 /W:3 /XD SiteReplication /XD SiteLogs /XD Administration /XD sitestatistics /XF calendar_secure.asp /XF navigation_editor.asp  /LOG+:logs\test.log


    goto :EOF

    :Syntax
    ECHO Usage:  _REP_SITE WEB_Site
    ECHO.
    ECHO Where:  "WEB_Site"   is the name of the folder you want to replicate
    ECHO                      i.e. _REP_SITE www.test.com
    ECHO.
    goto :END

    :END
    exit
like image 755
MG. Avatar asked May 04 '09 08:05

MG.


People also ask

How do I append to a batch file?

Content writing to files is also done with the help of the double redirection filter >>. This filter can be used to append any output to a file. Following is a simple example of how to create a file using the redirection command to append data to files.

How do I convert a TXT file to a batch file?

Click File and then Save, and then navigate to where you want to save the file. For the file name, type test. bat and if your version of Windows has a Save as type option, choose All files, otherwise it saves as a text file. Once you have completed these steps, click the Save button and exit notepad.

How do you append the output of a command to a file in Windows?

If you want to save the output from multiple commands to a single file, use the >> operator instead. This appends the output of a command to the end of the specified file, if it already exists. If the file doesn't exist, it creates a new one.


1 Answers

Something like:

type textfile.txt >> test.log

?

(Note that in the batch file it looks like you're currently creating two separate log files. Is that deliberate?)

Alternatively, if you need to copy the files elsewhere you can just do:

copy test.log+textfile.txt destination.log

That creates destination.log from test.log with textfile.log appended on the end.

like image 57
Jon Skeet Avatar answered Sep 28 '22 04:09

Jon Skeet