Sign in to follow this  
Followers 0
pghbrea

Why won't my script complete?

12 posts in this topic

#1 ·  Posted (edited)

I've been learning by reading and "I think" doing ok at it. I have this script that's meant to identify the status of two processes running. It always generates results but will not complete. Sometimes I get 60 results, sometimes 150 but there's always at least 100 hosts that exist in the txt file that have no results. You can see I was doing some testing and I eventually plan to look into a GUI to capture the username/password to be used.

I've removed any identifying data and made it general.

#include <GUIConstants.au3>
#include <array.au3>
#include <FileConstants.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
 
 
Local $data, $data1, $pid, $pid1, $res, $res1
 
 
$output_file = @MyDocumentsDir & '\file.csv'
$read_file = FileOpen (@MyDocumentsDir & '\ips.txt', 0)
 
FileDelete ($output_file)
$write_file = FileOpen ($output_file, 1)
$v = _FileCountLines (@MyDocumentsDir & '\ips.txt')
$x = 1
 
FileWrite ($write_file, 'HOST' & ',' & 'AV' & "," & 'LOGS' & @CRLF)
 
Do
$res = 0
$res1 = 0
$data = 0
$data1 = 0
; MsgBox (0, 'Test', $res & '  &  ' & $res1)
$ip = FileReadLine ($read_file, $x)
$pid = RunAs('username', 'domain', 'password', 0, 'sc \\'&$ip&' query "servicename"', '', @SW_HIDE, 2)
Do
$data &= StdOutRead($pid)
Until @error
 
; MsgBox(0, 'result', $data)
 
$pid1 = RunAs('username', 'domain', 'password', 0, 'sc \\'&$ip&' query "servicename"', '', @SW_HIDE, 2)
Do
$data1 &= StdoutRead($pid1)
Until @error
 
; MsgBox(0, 'result', $data1)
 
If StringInStr($data, 'running') Then
$res = 'running'
Elseif StringInStr($data, 'does not exist') Then
$res = 'not running'
ElseIf StringInStr($data, 'unavailable') Then
$res = 'RPC error'
EndIf
 
If StringInStr($data1, 'running') Then
$res1 = 'running'
Elseif StringInStr($data1, 'does not exist') Then
$res1 = 'not running'
ElseIf StringInStr($data1, 'unavailable') Then
$res1 = 'RPC error'
EndIf
 
; MsgBox (0, 'Result', $res & '  &  ' & $res1)
; MsgBox (0, 'Resut', 'Not a Windows Server')
$x = $x+1
; MsgBox (0, 'value x', $x)
; MsgBox (0, 'value v', $v)
 
FileWrite ($write_file, $ip & ',' & $res & "," & $res1 & @CRLF)
 
Until $x = $v+1
FileClose ($output_file)
FileClose ($write_file)
Edited by pghbrea

Share this post


Link to post
Share on other sites



Welcome to the AutoIt forum! :D

Using code tags with greatly help the clarity of your code. By using autoit code tags [ autoit ] ; code goes here [ /autoit ] (remove the spaces) you can have a box like this.

Local $variable = "example" ;<<<<example

:)


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Bump asking for any ideas?

Share this post


Link to post
Share on other sites

I would use some de-bugging.  You have a lot of nested "do" loops.  Are you sure they can all be satisfied?  If one is not it will be an infinite loop and make it so your script does not end.


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

I would add Opt("TrayIconDebug", 1) and check how things are going while the script runs, maybe even slow down the program with a bunch of sleeps, or MsgBoxes to see where things may go wrong

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I would also write $x and $v to the console to see what numbers you are getting.  If  $x does not equal $v+1 it will run forever.

something like this:

consolewrite(@crlf& "***This is $x "& $x &"***" & @crlf)
consolewrite(@crlf& "***This is $v "& $v &"***" & @crlf)

That will show their values on separate lines every time the do loop runs.  I would add it just before the

Until $x = $v+1




			
				


	Edited  by Jfish
	
	

			
		

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

Thanks for the recommendation. I found the problem but am not sure how to resolve it. What seems to be occuring is the runas statement is completing before the stdoutread can get the information it needs so I seem to be stuck in that Do loop

 
Do 
$data1 &= StdoutRead($pid1) 
Until @error

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

It simply means that your shelled program doesn't finish.

Try without the @sw_hide and read both STDOUT and STDERR to see if there are any errors shown:

$pid1 = RunAs('username', 'domain', 'password', 0, 'sc \\'&$ip&' query "servicename"', '',Default, 8)

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I used @SW_MAXIMIZE after messing around with your recommendation without success.

What seems to be happening is the shelled program does finish yet the Do loop does not get the result.

Share this post


Link to post
Share on other sites

Another handy way to troubleshoot, is to write values to a txt or ini file at various points throughout your code, this avoids issues of the console or msgbox.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

I used @SW_MAXIMIZE after messing around with your recommendation without success.

What seems to be happening is the shelled program does finish yet the Do loop does not get the result.

 

Add some sleep lines to your code and a msgbox to see if the result of the shell executed exe is reaching your script. This could be autoit or your shelled exe.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

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  
Followers 0