此.bat文件用于网站复制,将文件从开发转移到生产,然后生成包含作业统计信息的日志文件。我想在日志文件中包含踢出执行.bat的用户的名字。这可能吗。
到目前为止,我只能在日志文件的文件名中包含用户名,%USERNAME%.log。
@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
答案 0 :(得分:2)
这应该有效:
ECHO %USERNAME% >> LOG_FILE_NAME.LOG
答案 1 :(得分:0)
setlocal
set log=file.name
echo. >> %log%
date /t >> %log%
time /t >> %log%
echo user: %username% >> %log%
::...
endlocal
当然,“file.name”本身可以包含变量值。