Jump to content
Sign in to follow this  
Gnat

Script crashing...

Recommended Posts

Gnat

I have written a script that has several functions in it and one of them is causing the script to crash...Can somebody maybe point me in the right direction to either prevent the crash or to figure out what is actually causing the crash...

The first couple of functions in the script just query AD for all servers in a given OU, then sorts them alphabetically, and then pulls out a certain number of those based on the server location. All of that works great!

The function that is crashing is were I am attempting to scrape out of the Application event logs only Errors that happened on the previous day. After this runs for several servers (usually ~90) then it crashes with the following in the Application event log:

Source: DrWatson

Event ID: 4097

Description: The application, C:\TEMP\EventLogs.exe, generated an application error The error occurred on 05/22/2008 @ 13:47:48.731 The exception generated was c0000005 at address 7C81BD02 (ntdll!ExpInterlockedPopEntrySListFault)

Here is the offending code:

Func _AppLogCapture()

$logfile = FileOpen('C:\Program Files\Scripts\EventLogs\applogs.txt', 2)

$calc1date = _DateAdd('D', -1, _NowCalcDate())

$calc2date = _DateAdd('D', -2, _NowCalcDate())

$1daybefore = StringMid($calc1date, 6, 2) & '/' & StringRight($calc1date, 2) & '/' & StringLeft($calc1date, 4)

$2daybefore = StringMid($calc2date, 6, 2) & '/' & StringRight($calc2date, 2) & '/' & StringLeft($calc2date, 4)

$count = IniReadSection('C:\Program Files\Scripts\EventLogs\dallasservers.ini', 'Servers')

For $i = 1 to $count[0][0] Step 1

$hostname = IniRead('C:\Program Files\Scripts\EventLogs\dallasservers.ini', 'Servers', $i, '')

$applog = _EventLog__Open($hostname, 'Application')

If $applog <> 0 Then

$totalevt = _EventLog__Count($applog)

For $j = $totalevt to 1 Step -1

$event = _EventLog__Read($applog, True, False)

If $event[2] = $1daybefore and $event[7] = 1 Then

FileWriteLine($logfile, $event[2] & ' ' & $event[3] & ',' & $event[6] & ',' & $event[8] & ',' & $event[9] & ',' & $event[10] & ',' & $event[11] & ',' & $event[12] & ',' & $event[13])

ElseIf $event[2] = $2daybefore Then

ExitLoop

EndIf

Next

_EventLog__Close($applog)

EndIf

Next

FileClose($logfile)

EndFunc; _AppLogCapture()

Any/all help would be greatly appreciated...

Share this post


Link to post
Share on other sites
Kerros

#AutoIt3Wrapper_run_debug_mode=Y

That will should where you are in the script in the console. Add that at the top of your script.


Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites
martin

I have written a script that has several functions in it and one of them is causing the script to crash...Can somebody maybe point me in the right direction to either prevent the crash or to figure out what is actually causing the crash...

The first couple of functions in the script just query AD for all servers in a given OU, then sorts them alphabetically, and then pulls out a certain number of those based on the server location. All of that works great!

The function that is crashing is were I am attempting to scrape out of the Application event logs only Errors that happened on the previous day. After this runs for several servers (usually ~90) then it crashes with the following in the Application event log:

Source: DrWatson

Event ID: 4097

Description: The application, C:\TEMP\EventLogs.exe, generated an application error The error occurred on 05/22/2008 @ 13:47:48.731 The exception generated was c0000005 at address 7C81BD02 (ntdll!ExpInterlockedPopEntrySListFault)

Here is the offending code:

Func _AppLogCapture()

$logfile = FileOpen('C:\Program Files\Scripts\EventLogs\applogs.txt', 2)

$calc1date = _DateAdd('D', -1, _NowCalcDate())

$calc2date = _DateAdd('D', -2, _NowCalcDate())

$1daybefore = StringMid($calc1date, 6, 2) & '/' & StringRight($calc1date, 2) & '/' & StringLeft($calc1date, 4)

$2daybefore = StringMid($calc2date, 6, 2) & '/' & StringRight($calc2date, 2) & '/' & StringLeft($calc2date, 4)

$count = IniReadSection('C:\Program Files\Scripts\EventLogs\dallasservers.ini', 'Servers')

For $i = 1 to $count[0][0] Step 1

$hostname = IniRead('C:\Program Files\Scripts\EventLogs\dallasservers.ini', 'Servers', $i, '')

$applog = _EventLog__Open($hostname, 'Application')

If $applog <> 0 Then

$totalevt = _EventLog__Count($applog)

For $j = $totalevt to 1 Step -1

$event = _EventLog__Read($applog, True, False)

If $event[2] = $1daybefore and $event[7] = 1 Then

FileWriteLine($logfile, $event[2] & ' ' & $event[3] & ',' & $event[6] & ',' & $event[8] & ',' & $event[9] & ',' & $event[10] & ',' & $event[11] & ',' & $event[12] & ',' & $event[13])

ElseIf $event[2] = $2daybefore Then

ExitLoop

EndIf

Next

_EventLog__Close($applog)

EndIf

Next

FileClose($logfile)

EndFunc; _AppLogCapture()

Any/all help would be greatly appreciated...

What happens if _EventLog__Read fails? It's not clear to me from the help. If it doesn't return an array then the code will have a problem.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Gnat

#AutoIt3Wrapper_run_debug_mode=Y

That will should where you are in the script in the console. Add that at the top of your script.

Thanks, that is a new one to me, but the script is not crashing in the logic of it, but it is almost as though I am running out of memory for some reason.

Any other ideas?

Share this post


Link to post
Share on other sites
Gnat

What happens if _EventLog__Read fails? It's not clear to me from the help. If it doesn't return an array then the code will have a problem.

If it fails, it returns a 0 (zero) and no array. Hence the reason for the "If $applog <> 0 Then" statement that checks that.

Share this post


Link to post
Share on other sites
martin

If it fails, it returns a 0 (zero) and no array. Hence the reason for the "If $applog <> 0 Then" statement that checks that.

No, that's IniRead, I said _EventLog__Read. it's not checked here

$event = _EventLog__Read($applog, True, False)
If $event[2] = $1daybefore and $event[7] = 1 Then
[/code


            
                


    Edited  by martin
    
    

            
        

        
            
                
                    

        
        
            
                
                    
                
            
            
            
        
    


                
            
            
                
                    
                    
                    
                
                
                    
                
            
        

        
            




  
  
    Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
  


        
    

    
        
            Share this post
            
            Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    

    

                    
                        
                            



(adsbygoogle = window.adsbygoogle || []).push({});

                        
                    
                
                    
                    
                    






    

    
        
            
PsaltyDS
              

    
        
    
             27
    
        
    

        
        
            

    
        
    

        
    
    
        
PsaltyDS   

    
        
    
             27
    
        
    

        
        
            
                Most Venerable Penguin
            
            

            
                

    
        
    

            
            MVPs
            
                
            
            
                

    
        
    
             27
    
        
    

                13,093 posts
                
                

            
        
    
    
        


    

    
        
            
                
                
                
                    
                
                
            
        

        
            Posted 
            
                
                    (edited)
                
                
            
        
    

    


    
        
        
            
What happens if _EventLog__Read fails? It's not clear to me from the help. If it doesn't return an array then the code will have a problem.
It returns an array for failure also, with [0] = False.  Testing it might look like:                $event = _EventLog__Read($applog, True, False)
                If $event[0] Then
                    If $event[2] = $1daybefore And $event[7] = 1 Then
                        FileWriteLine($logfile, $event[2] & ' ' & $event[3] & ',' & $event[6] & ',' & $event[8] & ',' & $event[9] & ',' & _
                            $event[10] & ',' & $event[11] & ',' & $event[12] & ',' & $event[13])
                    ElseIf $event[2] = $2daybefore Then
                        ExitLoop
                    EndIf
                Else
                    MsgBox(16, "Error", "_EventLog__Read failed.")
                EndIf

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Gnat

It returns an array for failure also, with [0] = False. Testing it might look like:

$event = _EventLog__Read($applog, True, False)
                If $event[0] Then
                    If $event[2] = $1daybefore And $event[7] = 1 Then
                        FileWriteLine($logfile, $event[2] & ' ' & $event[3] & ',' & $event[6] & ',' & $event[8] & ',' & $event[9] & ',' & _
                            $event[10] & ',' & $event[11] & ',' & $event[12] & ',' & $event[13])
                    ElseIf $event[2] = $2daybefore Then
                        ExitLoop
                    EndIf
                Else
                    MsgBox(16, "Error", "_EventLog__Read failed.")
                EndIf

:)

After turning on the debug_mode, I get the following error

!>11:36:57 AutoIT3.exe ended.rc:-1073741819

>Exit code: -1073741819 Time: 436.543

Any help?

Thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×