You are not logged in.

#1 28 Nov 2007 19:22

drifty
Member
Registered: 28 Nov 2007
Posts: 122

adding a user name to the RoboCopy log

I use RoboCopy and a project.rcj file to copy files from various desktops to a server. I would like to add the user name (the persopn the desktop is assigned to) to the log file when the copy is executed. Any help on this would be greatly appreciated.
-Frank

Offline

#2 29 Nov 2007 14:17

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: adding a user name to the RoboCopy log

In general you can append text to a file with a command such as this:

echo:[your text here] >> logfile.log

... I'm presuming you already have a mechanism for determining to whom a given computer is assigned.

Last edited by bluesxman (29 Nov 2007 14:18)


cmd | *sh | ruby | chef

Offline

#3 29 Nov 2007 16:10

drifty
Member
Registered: 28 Nov 2007
Posts: 122

Re: adding a user name to the RoboCopy log

That works for getting the text into the log. Yes you are correct that we know the name of the user when we start RoboCopy but I would like to prompt for this information. For example when the batch file is started and kicks off RoboCopy - when the copy finishes I would like to have it pause and display the results (as it does now) then prompt for the Owners Name then the name of the person who ran the copy (as they will be different). Then have this information appended to the log file.
Again any help would be greatly appreciated.
-Frank

Offline

#4 29 Nov 2007 17:30

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: adding a user name to the RoboCopy log

Something like this should be sufficient:

set _owner=
:ownerloop
set /p "_owner=Please specify the owner >: "
if not defined _owner (echo:Owner can't be blank&goto :ownerloop)
(echo:%_owner%) >> logfile.log

... but if you're doing this for lots of users you might want to investigate automating this step by looking the name up from a list of names with (for example) IP addresses or host names.

Last edited by bluesxman (29 Nov 2007 17:32)


cmd | *sh | ruby | chef

Offline

#5 29 Nov 2007 19:16

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: adding a user name to the RoboCopy log

When running these sort of jobs I like to separate out all the logfiles by using the %computername% variable as part of the logfile name

echo:[your text here] >> \\server\share$\log%computername%.log

You can set the robocopy log file destination in the same way

Offline

#6 29 Nov 2007 19:22

drifty
Member
Registered: 28 Nov 2007
Posts: 122

Re: adding a user name to the RoboCopy log

Thanks much - I am getting closer to what may actually work.
Below is the batch file that I have now and it seems to work except I the log file is made up using a job number _ external drive that files were copied to.log (AB561_2345699.log). The name does change and is used in the Robocopy command line and I have to repeat it for each set /p INPUT line below so it appends to the log file. Although this works it isn't very efficient. Any way to make this a little smoother?
-Frank

================================================================
cls
@echo off
rem Created by: Frank Smith
rem Created for: SO Number AB561
rem Created on: 11/29/2007


rem --------This is the RoboCopy command that will be executed:-----------

h:\AB561\Scripts\robocopy.exe /Job:"h:\AB561\Scripts\LT ED Onsite Filtered.rcj" "\\Eim1\EIM1C\ActiveTraining" "h:\AB561\GS\Eim1\EIM1C\ActiveTraining" /Log+:"h:\AB561\Logs\AB561_2345699.log"   
h:\AB561\Scripts\robocopy.exe /Job:"h:\AB561\Scripts\LT ED Onsite Filtered.rcj" Z:\ "h:\AB561\PS\Doe, John\Z" /Log+:"h:\AB561\Logs\AB561_2345699.log"   
h:\AB561\Scripts\robocopy.exe /L /Job:"h:\AB561\Scripts\LT ED Onsite Filtered.rcj" "\\Eim1\EIM1C\LFC Training" "h:\AB561\LIST\Eim1\EIM1C\LFC Training" /Log+:"h:\AB561\Logs\AB561_2345699.log"   

rem -----------------------------------------------------------------------
rem The following commands will be executed after the copy and will append the log file.

set INPUT=
set /P INPUT=Type Machine ID: %=%
echo     Machine ID   - %INPUT% >> "I:\AB561\Logs\AB561_2345699.log"
set /P INPUT=Type Custodian Last Name, First Name: %=%
echo     Custodian    - %INPUT% >> "I:\AB561\Logs\AB561_2345699.log"
set /P INPUT=Type KO Asset Tag: %=%
echo     KO Asset Tag - %INPUT% >> "I:\AB561\Logs\AB561_2345699.log"
set /P INPUT=Type KO Engineer Initials: %=%
echo     KO Engineer  - %INPUT% >> "I:\AB561\Logs\AB561_2345699.log"

Pause

======================================================

Offline

#7 30 Nov 2007 18:56

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: adding a user name to the RoboCopy log

Having to type the machine details seems awfully clunky to me, but I don't know enough about what you're doing.

To tidy up the code you do have, I would do something like this:

@echo off
cls
rem Created by: Frank Smith
rem Created for: SO Number AB561
rem Created on: 11/29/2007

set job=AB561
set drive=2345699

REM one could pass the drive as a command line parameter and use it thus:
REM set drive=%1

set robocopy=h:\%job%\Scripts\robocopy.exe
set filter=h:\%job%\Scripts\LT ED Onsite Filtered.rcj

REM Based on your original question I thought you were logging all to one file, but your script would indicate otherwise

set hlog=h:\%job%\Logs\%job%_%drive%.log
set ilog=i:\%job%\Logs\%job%_%drive%.log

rem --------This is the RoboCopy command that will be executed:-----------

"%robocopy%"    /Job:"%filter%" "\\Eim1\EIM1C\ActiveTraining" "h:\%job%\GS\Eim1\EIM1C\ActiveTraining" /Log+:"%hlog%"   
"%robocopy%"    /Job:"%filter%" Z:\                           "h:\%job%\PS\Doe, John\Z"               /Log+:"%hlog%"   
"%robocopy%" /L /Job:"%filter%" "\\Eim1\EIM1C\LFC Training"   "h:\%job%\LIST\Eim1\EIM1C\LFC Training" /Log+:"%hlog%"   

rem -----------------------------------------------------------------------
rem The following commands will be executed after the copy and will append the log file.

set /p "machineID=Type Machine ID: "
set /p "custodian=Type Custodian Last Name, First Name: "
set /p "asset_tag=Type KO Asset Tag: "
set /p "engineerI=Type KO Engineer Initials: "

(
    echo:    Machine ID   - %machineID%
    echo:    Custodian    - %custodian%
    echo:    KO Asset Tag - %asset_tag%
    echo:    KO Engineer  - %engineerI%
) >> "%ilog%"
pause

... I've little doubt with more information there's plenty one could do to automate this a bit better.


cmd | *sh | ruby | chef

Offline

#8 30 Nov 2007 21:05

drifty
Member
Registered: 28 Nov 2007
Posts: 122

Re: adding a user name to the RoboCopy log

Thanks for the help - seems to be working once I made a few adjustments.
What I do with this is collect files from entire drives, specific folders or shares in remote locations. I only have an external drive that I connect via USB and before I go to a site I put RoboCopy and what ever scripts and RCJ file on it in a specific folder structure.
Thanks to your assistance I am able to make this a little more efficient and hopefully more consistant by not having several people write the batch files by hand each time. If I could find a way for the batch file to identify the drive letter of the external drive it is executed from and change the letter in the line (H:\ to F:\ for example) that would elimate a manual step. Also if I could capture the log file location from the end of the RoboCopy script (that is actually created by a different application) and make it a variable that I could use then some of the issues I have with people typing this in wrong would be resolved also. Such as H:\AB561\Logs\PC_Collection.txt from this line:
H:\AB561\Scripts\robocopy.exe /Job:"H:\AB561\Scripts\LT ED Onsite Filtered.rcj" "C:\temp" "H:\AB561\PC\Doe, John\C\temp" /Log+:"H:\AB561\Logs\PC_Collection.txt"

-Frank

Offline

#9 03 Dec 2007 13:31

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: adding a user name to the RoboCopy log

This is how I'd go about getting the drive letter.  It relies on you labelling your backup devices in a specific manner.  For the example tag in the following script, you'd want to label them in this fashion:
    BX_2345699
    BX_2345700
    BX_2345735

@echo off
setlocal enabledelayedexpansion

REM whatever you choose to tag your discs with.

set drive_tag=BX

REM character that delimits the tag component from the name component of the drive label
set tag_delim=_

REM these won't be blank at the end if this all goes to plan
set drive_name=
set drive_letter=

set drive_conflict=0

REM scan all potential drive letters...
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
    cls
    echo:Scanning for a backup device ... [%%a]
    REM for each letter, attempt to get the drive volume information
    for /f "usebackq tokens=5* delims= " %%v in (`vol %%a: 2^>nul ^| find /i "Volume in drive %%a is"`) do (
        echo:%%w | findstr /i /b "%drive_tag%%tag_delim%" >nul
        if !errorlevel! EQU 0 (
        REM we have a match
            if not defined drive_letter (
            REM if this is the first match we've found...
                set drive_letter=%%a:
                REM get the drive name, minus the tag...
                for /f "tokens=1* delims=%tag_delim%" %%x in ("%%~w") do set drive_name=%%y
            ) ELSE (
            REM if this is not the first matched letter, we have a conflict
                set drive_conflict=1
                set drive_letter=!drive_letter!, %%a:
            )
        )
    )
)

cls

if not defined drive_letter (
REM nothing matched
    echo:ERROR: No suitable drive was found.
) ELSE (
    if "%drive_conflict%" EQU "1" (
    REM more than one device matched
        echo:ERROR: Conflict found - these devices are all tagged "%drive_tag%":
        echo:       %drive_letter%
        echo:       Please remove all but one backup device.
        set drive_letter=
        set drive_name=
    ) ELSE (
    REM just one device matched
        echo:SUCCESS: Drive %drive_letter% seems to be disk %drive_name%.
    )
)
pause

As for gleaning the robocopy log location, perhaps you could furnish an sample robocopy script?

Last edited by bluesxman (03 Dec 2007 15:19)


cmd | *sh | ruby | chef

Offline

#10 03 Dec 2007 21:09

drifty
Member
Registered: 28 Nov 2007
Posts: 122

Re: adding a user name to the RoboCopy log

This works great...thanks much.
I have some additional work to do and when I am done I will post what I have.
-Frank

Offline

#11 04 Dec 2007 16:41

drifty
Member
Registered: 28 Nov 2007
Posts: 122

Re: adding a user name to the RoboCopy log

I was going well until I switched between a mapped drive letter to a server share.

For a drive letter I need to create one version with a :\ and another without for example C:\ and just C. The colon causes an error when it is included for the source for the copy path. In this output example the Copy path is "F:\AB561\PC\Doe, Jon\c:\" but should be:
F:\AB561\Scripts\robocopy.exe /Job:"F:\AB561\Scripts\LT ED Onsite Filtered.rcj" C:\ "F:\AB561\PC\Doe, John\C" /Log+:"F:\AB561\Logs\PC_123456.txt"   

One with a folder should be:
F:\AB561\Scripts\robocopy.exe /Job:"F:\AB561\Scripts\LT ED Onsite Filtered.rcj" "C:\temp" "F:\AB561\PC\Doe, John\C\temp" /Log+:"F:\AB561\Logs\PC_123456.txt"   

A server\Share should be
F:\AB561\Scripts\robocopy.exe /Job:"F:\AB561\Scripts\LT ED Onsite Filtered.rcj" "\\Eim1\EIM1C\ActiveTraining" "F:\AB561\GS\Eim1\EIM1C\ActiveTraining" /Log+:"F:\AB561\Logs\GS_123456.txt"   

The colon needs to be included in some places but removed in others. This is the latest results:

SUCCESS: Drive F: seems to be disk 123456.
Copy Path:
"F:\AB561\PC\Doe, Jon\c:\"
Log File Path:
F:\AB561\Logs\PC_123456.txt"
Press any key to continue . . .

Job File : F:\AB561\SCRIPTS\LT ED ONSITE FILTERED.RCJ

Log File : F:\AB561\Logs\PC_123456.txt


2007/12/04 09:22:53 ERROR 123 (0x0000007B) Accessing Source Directory C:\" F:\AB 561\PC\Doe,\
The filename, directory name, or volume label syntax is incorrect.
.
    - - - - - - - - - - - - - - - - - - - - - -
    -      The Copy IS COMPLETE               -
    -  REVIEW THE LONG FILE FOR DETAILS       -
    -  F:\AB561\Logs\PC_123456.txt"                                  -
    - - - - - - - - - - - - - - - - - - - - - -
.
Press any key to continue . . .


================Current batch file==============

cls
@echo off

REM Created December 03 2007


REM = Step 1 = ===== EDIT / VERIFY THESE VARIABLES BEFORE RUNNING THE BATCH FILE  ==========

REM    ###############################################################################
REM    # Set the default value for the Project and the                                        #
REM    # Asset Tag (Asset_Tag) for the Destination Drive (usually the external drive)         #
REM    # that will be used for the collection. The Destination Drive must have this same name #
REM    # prefixed with KO_ For example KO_123456 for asset number 123456.                     #        
REM    ###############################################################################

set Collection_Type=PC
set Project_Alias=AB561
set Asset_Tag=KO_123456
set Job_File=LT ED Onsite Filtered.rcj

echo .	   
echo     - - - - - - - - - - - - - - - - - - - - - -
echo     -  At the prompt type in the requested    -
echo     - information to start the collection.    -
echo     - - - - - - - - - - - - - - - - - - - - - -
echo .

set /P "Source=Type Source (C:\, D:\, \\Server\Share): "
set /P "Custodian=Type Custodian Name: Last, First: "
set /p "Engineer_Initials=Type KO Engineer Initials: "
set /P "Machine_Type=Type Machine Type (Laptop, Desktop): "
set /p "Machine_ID=Type Machine ID: "
set /P "Operating_System=Type Operating System (Win2000, XP, Vista) : "
set /P "Collection_Location=Type Collection Location (Company Name, Department, etc.):  "

Code:
@echo off
setlocal enabledelayedexpansion

REM KO is the prefix for the Asset (external drive or destination)

set drive_tag=KO

REM character that delimits the tag component from the name component of the drive label
set tag_delim=_

REM these won't be blank at the end if this all goes to plan
set drive_name=
set drive_letter=

set drive_conflict=0

REM scan all potential drive letters...
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
    cls
    echo:Scanning for the Destination Drive ... [%%a]
    REM for each letter, attempt to get the drive volume information
    for /f "usebackq tokens=5* delims= " %%v in (`vol %%a: 2^>nul ^| find /i "Volume in drive %%a is"`) do (
        echo:%%w | findstr /i /b "%drive_tag%%tag_delim%" >nul
        if !errorlevel! EQU 0 (
        REM we have a match
            if not defined drive_letter (
            REM if this is the first match we've found...
                set drive_letter=%%a:
                REM get the drive name, minus the tag...
                for /f "tokens=1* delims=%tag_delim%" %%x in ("%%~w") do set drive_name=%%y
            ) ELSE (
            REM if this is not the first matched letter, we have a conflict
                set drive_conflict=1
                set drive_letter=!drive_letter!, %%a:
            )
        )
    )
)

cls
if not defined drive_letter (
REM nothing matched
    echo:ERROR: No suitable drive was found.
) ELSE (
    if "%drive_conflict%" EQU "1" (
    REM more than one device matched
        echo:ERROR: Conflict found - these devices are all tagged "%drive_tag%":
        echo:       %drive_letter%
        echo:       Please remove all but one external device.
        set drive_letter=
        set drive_name=
    ) ELSE (
    REM just one device matched
        echo:SUCCESS: Drive %drive_letter% seems to be disk %drive_name%.
    )
)

REM I created these line to display the paths that were created:
SET Log=%drive_letter%\%Project_Alias%\Logs\%Collection_Type%_%drive_name%.txt"

echo Copy Path:
echo "%drive_letter%\%Project_Alias%\%Collection_Type%\%Custodian%\%Source%" 

echo Log File Path:
echo %Log%

pause


(
    echo: ---------------------------------------------------------------------------
    echo:           Active Collection Log
    echo: --------------------------------------------------------------------------- 
    echo: Project Alias..........%Project_Alias% 
    echo: Collection Type........%Collection_Type%  
    echo: Custodian..............%Custodian%     
    echo: Machine Type...........%Machine_Type%  
    echo: Machine ID.............%Machine_ID%
    echo: Operating System.......%Operating_System%
    echo: KO Asset Tag...........%drive_name%
    echo: KO Engineer Initials:..%Engineer_Initials%
REM echo: Location...............%Collection_Location%  
) >> "%log%"



REM = Step 2 = ===== EDIT / VERIFY THE RoboCopy Command Line BEFORE RUNNING THE BATCH FILE ==========

REM    ###############################################################################
REM    # For Manual editing - Edit the line below or replace it by pasting a newline from the RoboCopy template    #
REM    ###############################################################################

%drive_letter%\%Project_Alias%\Scripts\robocopy.exe /Job:"%drive_letter%\%Project_Alias%\Scripts\%Job_File%" "%Source%" "%drive_letter%\%Project_Alias%\%Collection_Type%\%Custodian%\%Source%" /Log+:"%drive_letter%\%Project_Alias%\Logs\%Collection_Type%_%drive_name%.txt"	

REM = Step 3 = ===== SAVE THIS FILE AS COLLECTION.BAT AND RUN TO START THE COLLECTION           

COLOR A 
echo .

echo     - - - - - - - - - - - - - - - - - - - - - -
echo     -      The Copy IS COMPLETE               -  
echo     -  REVIEW THE LONG FILE FOR DETAILS       -
echo     -  %log%                                  -
echo     - - - - - - - - - - - - - - - - - - - - - -

echo .


Pause

REM = REFERENCE INFORMATION ===================================================================================

REM    -----------------------------------------------------------------------------------------
REM    - The Examples below are base on the  Number of AB561 and the external drive Asset -
REM    - Number 2345699 that produce the approporiate log file.                                -
REM    -----------------------------------------------------------------------------------------

REM A typical script for a PC collection where the source drive is C:\ and destination is external drive h:\ 
REM H:\AB561\Scripts\robocopy.exe /Job:"H:\AB561\Scripts\LT ED Onsite Filtered.rcj" C:\ "H:\AB561\PC\Doe, John\C" /Log+:"H:\AB561\Logs\PC_Collection.txt"	

REM A typical script for a Group Share collection where the source path is "\\Eim1\EIM1C\ActiveTraining" and destination is external drive h:\
REM H:\AB561\Scripts\robocopy.exe /Job:"H:\AB561\Scripts\LT ED Onsite Filtered.rcj" "\\Eim1\EIM1C\ActiveTraining" "H:\AB561\GS\Eim1\EIM1C\ActiveTraining" /Log+:"H:\AB561\Logs\GS_Collection.txt"	

REM A typical script for a Personal Share collection where the custodian is Doe, John the source path has been mapped to Z:\ and destination is external drive h:\
REM H:\AB561\Scripts\robocopy.exe /Job:"H:\AB561\Scripts\LT ED Onsite Filtered.rcj" Z:\ "H:\AB561\PS\Doe, John\Z" /Log+:"H:\AB561\Logs\PS_Collection.txt"	

REM A typical script for a GS "List" collection where the source path is \\Eim1\EIM1C\LFC Trainingand destination is external drive h:\
REM Notice the addition of the /L switch "List only" - don't copy, timestamp or delete any files.   
REM H:\AB561\Scripts\robocopy.exe /L /Job:"H:\AB561\Scripts\LT ED Onsite Filtered.rcj" "\\Eim1\EIM1C\LFC Training" "H:\AB561\LIST\Eim1\EIM1C\LFC Training" /Log+:"H:\AB561\Logs\LIST_Collection.txt"	

===============
So I think I need to find a way to remove the :\ characters from the Source and create two variables. One with and one without?
-Frank

Offline

#12 05 Dec 2007 14:32

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: adding a user name to the RoboCopy log

After this section ...

set /P "Source=Type Source (C:\, D:\, \\Server\Share): "
set /P "Custodian=Type Custodian Name: Last, First: "
set /p "Engineer_Initials=Type KO Engineer Initials: "
set /P "Machine_Type=Type Machine Type (Laptop, Desktop): "
set /p "Machine_ID=Type Machine ID: "
set /P "Operating_System=Type Operating System (Win2000, XP, Vista) : "
set /P "Collection_Location=Type Collection Location (Company Name, Department, etc.):  "

... insert a line like this ...

set "target=%drive_letter%\%Project_Alias%\%Collection_Type%\%Custodian%\%Source::=$%"

... and replace all subsequent occurances of "%drive_letter%\%Project_Alias%\%Collection_Type%\%Custodian%\%Source%" with "%target%" (quotes included).   See if that solves it.

PS - please use the CODE tags around sections of code in your posts!


cmd | *sh | ruby | chef

Offline

Board footer

Powered by