Login script logging acting weird

Microsoft Windows server 2008 standard
February 4, 2010 at 07:50:17
Specs: Windows XP
I have a login script that maps a few drives and
sets a few registry keys. Since some of the
drive mappings weren't working, I made it
create a log and save a history like so:

setlocal enabledelayedexpansion
for /l %%i in (8,-1,0) do set /a j=%%i+1 && move /y "%USERPROFILE%\login%%i.log" "%USERPROFILE%\login!j!.log" >nul
endlocal

>"%USERPROFILE%\login0.log" echo %USERDOMAIN%\%USERNAME% logged in on %DATE% at %TIME%
>>"%USERPROFILE%\login0.log" echo.
>>"%USERPROFILE%\login0.log" echo Map F drive
>>"%USERPROFILE%\login0.log" net use f: \\server\share 2>&1
>>"%USERPROFILE%\login0.log" echo Map I drive
>>"%USERPROFILE%\login0.log" net use i: \\server\share 2>&1
>>"%USERPROFILE%\login0.log" echo Map T drive
>>"%USERPROFILE%\login0.log" net use t: \\server\share 2>&1
>>"%USERPROFILE%\login0.log" echo Map U drive
>>"%USERPROFILE%\login0.log" net use u: \\server\share 2>&1

>>"%USERPROFILE%\login0.log" echo Set IE home page

if not exist "%USERPROFILE%\startpage.txt" (
	reg add "HKCU\Software\Microsoft\Internet 
Explorer\Main" /v "Start Page" /t REG_SZ /d
"\\server\share\intranet\startpage\index.html" /f >>"%USERPROFILE%\login0.log"
	) else echo Startpage disabled >>"%USERPROFILE%\login0.log"

>>"%USERPROFILE%\login0.log" echo Set GroupWise server address/port
reg add "HKCU\SOFTWARE\Novell\GroupWise\Login 
Parameters\TCP/IP Address" /ve /d 90.1.1.5 /f >>"%USERPROFILE%\login0.log"
reg add "HKCU\SOFTWARE\Novell\GroupWise\Login 
Parameters\TCP/IP Port" /ve /d 1677 /f >>"%USERPROFILE%\login0.log"

I thought it was pretty straightforward:
increment login?.txt by one, then create
login0.txt with info about what's going on, then
the output of the actual command. Right?

Well, yesterday I came across this:

DOMAIN\user logged in on Wed 02/03/2010 at 13:25:56.62

Map F drive
The command completed successfully.

The command completed successfully.

Map T drive
System error 85 has occurred.

The local device name is already in use.

Set IE home page

The operation completed successfully
Set GroupWise server address/port

The operation completed successfully

The operation completed successfully

So the "Map drive" text for I: and U: doesn't show up at all, and it totally skipped mapping the T drive. (I'm pretty sure the error 85 was about the U drive, because I map that twice for good measure.)

What's the deal? Any ideas?


See More: Login script logging acting weird

Report •


#1
February 4, 2010 at 07:57:02
Change ECHO OFF to ECHO ON and you will see which commands are skipped (if any) and what error message belongs to which command ...

Report •

#2
February 4, 2010 at 08:02:25
Wow. Duh. *slaps self*

As far as the underlying problem, batch file output relies on a
pointer, right? If the pointer is moved at the end of a command
and the next command starts thinking the pointer hasn't been
moved, might they drop their text in the same place in the file,
one overwriting the other?


Report •

#3
February 4, 2010 at 08:08:01
No... wait... echo IS on. But that doesn't affect command output,
just display. So how would I have the actual command written to
the logfile?

Surely it's something like 2>&1...


Report •

Related Solutions

#4
February 4, 2010 at 09:11:23
Perhaps the file was locked momentarily and thus the redirection failed.

Another explanation could be net outputting some control characters, like a backspace or perhaps only a cr instead of a crlf. But it seems a little inconsistent.

Is this persistent; do you get the same output every time it's run? Or is it a once off?

The script itself looks fine to me.

My boring little personal page(in progress)


Report •

#5
February 4, 2010 at 10:14:09
It doesn't happen every time, but I do get weird results like that
fairly frequently.

Report •

#6
February 4, 2010 at 10:29:01
The fact that this is intermittent does make me think it could
well be the file becoming locked.

Here is a way to test if the file is locked:

>> "%USERPROFILE%\test.log" 2>&1 (
    >"%USERPROFILE%\login0.log" echo %USERDOMAIN%\%USERNAME% logged in on %DATE% at %TIME%
    >>"%USERPROFILE%\login0.log" echo.
    >>"%USERPROFILE%\login0.log" echo Map F drive
    >>"%USERPROFILE%\login0.log" net use f: \\server\share 2>&1
    >>"%USERPROFILE%\login0.log" echo Map I drive
    >>"%USERPROFILE%\login0.log" net use i: \\server\share 2>&1
    >>"%USERPROFILE%\login0.log" echo Map T drive
    >>"%USERPROFILE%\login0.log" net use t: \\server\share 2>&1
    >>"%USERPROFILE%\login0.log" echo Map U drive
    >>"%USERPROFILE%\login0.log" net use u: \\server\share 2>&1
)

If "%USERPROFILE%\test.log" has anything in it at all, it will
most probably be file write errors along the lines of:

The process cannot access the file because it is
being used by another process.

If "test.log" gets locked, well then I have no idea on how
to even check.....

My boring little personal page(in progress)


Report •

#7
February 4, 2010 at 10:33:32
I have run into this my self. It is because Windows has a builtin map last drives and sometimes it maps the drives before the logon script runs. I just added...

net use t: /delete

before my net use to remove any already mapped drives.


Report •

#8
February 5, 2010 at 04:18:58
> As far as the underlying problem, batch file output relies
> on a
> pointer, right? If the pointer is moved at the end of a
> command
> and the next command starts thinking the pointer hasn't
> been
> moved, might they drop their text in the same place in
> the file,
> one overwriting the other?
>

I don't understand the meaning of "pointer" in a batchfile, but if you mean redirection (>,>> and <) just use >> instead of > and nothing gets lost.


Report •

#9
February 5, 2010 at 04:27:16
> No... wait... echo IS on. But that doesn't affect command
> output,
> just display. So how would I have the actual command
> written to
> the logfile?
>
> Surely it's something like 2>&1...
>

Yeah indeed ... if you want to debug a command inside a batch, doing redirection to a logfile already, you would still only see the command onscreen, not in that logfile.

My bad.

The 2> is just the error output, where > is the normal output, so the command itself is still missing ...


To really get the commands and all, you would need to remove all redirections on the commands that are failing (so, also the "> nul" if these are used on the suspected commands) and then run the script with ECHO OFF

If this outout is too long, or you need to have a good look, you can run:

C:\test.cmd > C:\test.log 2>&1


Report •


Ask Question