Agreed.
- ASB
-----Original Message-----
From: Niels Christiansen [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 16, 2001 1:06 PM
To: NT System Admin Issues
Subject: RE: Scripting expert please help
These limitations used to cause me a lot of grief in NT4.
I usually resolved the issue by putting the code that's to be executed by
the for statement into a subroutine and then let the for statement do a call
to the subroutine with the appropriate parameters (eg. %%i)
/\/iels
-----Original Message-----
From: Andrew S. Baker [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 16, 2001 5:32 AM
To: NT System Admin Issues
Cc: [EMAIL PROTECTED]
Subject: RE: Scripting expert please help
You will need to break up that single FOR line into a couple lines and
you'll be fine.
Problem #1 - You cannot use the %variable:~1,1% syntax with %0 - %9 or
%%A - %%Z variables.
Problem #2 - The variable substitution doesn't work the way you are
hoping.
Win2K allows you to change the way that substitution works. Here's
the relevant text from a "SET /?" command:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Finally, support for delayed environment variable expansion has been
added. This support is always disabled by default, but may be
enabled/disabled via the /V command line switch to CMD.EXE. See CMD
/?
Delayed environment variable expansion is useful for getting around
the limitations of the current expansion which happens when a line
of text is read, not when it is executed. The following example
demonstrates the problem with immediate variable expansion:
set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "%VAR%" == "after" @echo If you see this, it worked
)
would never display the message, since the %VAR% in BOTH IF statements
is substituted when the first IF statement is read, since it logically
includes the body of the IF, which is a compound statement. So the
IF inside the compound statement is really comparing "before" with
"after" which will never be equal. Similarly, the following example
will not work as expected:
set LIST=
for %i in (*) do set LIST=%LIST% %i
echo %LIST%
in that it will NOT build up a list of files in the current directory,
but instead will just set the LIST variable to the last file found.
Again, this is because the %LIST% is expanded just once when the
FOR statement is read, and at that time the LIST variable is empty.
So the actual FOR loop we are executing is:
for %i in (*) do set LIST= %i
which just keeps setting LIST to the last file found.
Delayed environment variable expansion allows you to use a different
character (the exclamation mark) to expand environment variables at
execution time. If delayed variable expansion is enabled, the above
examples could be written as follows to work as intended:
set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "!VAR!" == "after" @echo If you see this, it worked
)
set LIST=
for %i in (*) do set LIST=!LIST! %i
echo %LIST%
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
==============================================================
ASB - http://www.ultratech-llc.com/KB/?File=~MoreInfo.TXT
==============================================================
"The right word might be effective, but no word was ever as
effective as a rightly timed pause." -- Mark Twain
>-----Original Message-----
>From: Giang, Sonny [mailto:[EMAIL PROTECTED]]
>Sent: Thursday, August 16, 2001 2:31 AM
>To: NT System Admin Issues
>Subject: Scripting expert please help
>
>
>Hi,
>
>I need to convert a log file from an application (Called
>InterWorld) to the
>IIS format.
>
>The script I write is as follow:
>* Get current date,
>* Get Current time,
>* Copy yesterday logfile from the Interworld apps to where I
>want to convert
>* For every file copied Do the convert of the file via a
>procedure called
>MODIFY
>* Move the converted file to a archive directory.
>
>The problem I have is with the command below, which i tried
>to change the
>date format of the logfile from MM/DD/YYYY to YYYY-MM-DD
>
>for /F "tokens=1-20 delims=," %%a in (%1) do (set u=%%c & echo
>%u:~6,4%-%u:~0,2%-%u:~3,2% %%d %%a - w3svc1 %%f %%g %%m %%n
>%%o %%l 0 %%k
>%%j %%h 80 HTTP/1.1 - - %%q >> %1.txt)
>
>the output is some thing like this:
>D:\Scripts>(set u=08/14/2001 & echo :~6,4u:~0,2u:~3,21.txt )
>:~6,4u:~0,2u:~3,21.txt
>
>Can anyone please tell me what I've done wrong.
>
>the program and a sample input log file are attached.
>
>Program
>=============================================================
>===============
>===
>@echo on
>Set minday=1
>Set maxday=2
>set @source=z:\interworld\temp
>set @destin=i:\Prodbrk01
>
>:GetDate
>FOR /F "TOKENS=2" %%D IN ('DATE /T') DO SET @DATE=%%D
>
>:GetTime
>FOR /F %%T IN ('TIME /T') DO SET @TIME=%%T
>
>:CopyFile
>Robocopy %@source% %@destin% /MINAGE:%minday% /MAXAGE:%maxday%
>
>For %%z in (%@destin%\*.log) do (call :modify %%z)
>Goto End
>
>:modify
>setlocal
>if exist %1.txt (del %1.txt)
>echo #Software: Microsoft Internet Information Server 4.0 >> %1.txt
>echo #Version: 1.0 >> %1.txt
>echo #Date: %@DATE% %@TIME% >> %1.txt
>echo #Fields: date time c-ip cs-username s-sitename
>s-computername s-ip
>cs-method cs-uri-stem cs-uri-query sc-status sc-win32-status sc-bytes
>cs-bytes time-taken s-port cs-version cs(User-Agent)
>cs(Cookie) cs(Referer)
>>> %1.txt
>for /F "tokens=1-20 delims=," %%a in (%1) do (set u=%%c & echo
>%u:~6,4%-%u:~0,2%-%u:~3,2% %%d %%a - w3svc1 %%f %%g %%m %%n
>%%o %%l 0 %%k
>%%j %%h 80 HTTP/1.1 - - %%q >> %1.txt)
>
>copy %1 %@destin%\archive /y
>del %1
>Endlocal
>Goto end
>
>
>:end
>================================================
>Input logfile, (wrapped)
>================================================
>155.144.24.23,"",08/13/2001,23:58:42,InterWorld WebBroker/3.0.1.6
>#1,hqifsprodbrk01,155.144.24.23,63,63,73,192,200,GET,/WatchDo
>g.tem,-,"-","-"
>,< a6a4a5222262b27d2525c1082bf,-,10.0.9.34:8802
>155.144.24.23,"",08/14/2001,00:00:42,InterWorld WebBroker/3.0.1.6
>#1,hqifsprodbrk01,155.144.24.23,62,62,73,190,200,GET,/WatchDo
>g.tem,-,"-","-"
>,< a6a4a5132262b27d3138af2cc,-,10.0.9.19:8802
>================================================
>CAUTION
>
http://www.sunbelt-software.com/ntsysadmin_list_charter.htm