New to Forum - killing commands before default timeout

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
matt12582
Posts: 5
Joined: 02 Nov 2011 11:58

New to Forum - killing commands before default timeout

#1 Post by matt12582 » 02 Nov 2011 12:10

I write batch occasionally for fun occasionally for work
I'm handy with Win_32 command line but still need some help occasionally
I've been writing a few scripts for work as of late and am looking for some help in tweaking them

one script I have looks for an RDP session with QWINSTA

it searches about 60 citrix terminal servers in total, the only issue I run into is day to day usually a few servers are down at any given time and the timeout for the query seems to be a good 10-15 seconds before it reports that RPC is unavailable.
looking for a way to kill the command after say 2 seconds and just echo an error , and move on the next label via "goto"
here is a sample

:Start
ECHO -------------------------------------
ECHO ISMETA01
QWINSTA /Server:ismeta01 %profile%
Goto Next Server1
:Next Server1
ECHO -------------------------------------
ECHO ISMETA02
QWINSTA /Server:ismeta02 %profile%
Goto Next Server2

aGerman
Expert
Posts: 4705
Joined: 22 Jan 2010 18:01
Location: Germany

Re: New to Forum - killing commands before default timeout

#2 Post by aGerman » 02 Nov 2011 13:07

I don't have a solution. Since the batch file is waiting until the QWINSTA process is finished you cannot interrupt it.

You could try to run QWINSTA asynchronously (using START). Merge stdOut and stdErr and redirect both to a separate file for each server. At the end you could run a loop to check whether all instances of QWINSTA are already finished (TASKLIST). Now you could TYPE all files and remove them.

Of course it creates a lot of temporary files, but if you have to process a lot of servers it will probably save some time.

Regards
aGerman

matt12582
Posts: 5
Joined: 02 Nov 2011 11:58

Re: New to Forum - killing commands before default timeout

#3 Post by matt12582 » 02 Nov 2011 13:38

so something like

START /B QWINSTA /Server:ismeta01 %profile% >%temp%\ismeta01.txt

for each command

then once it kicks off the last command something like

:results
TYPE ISMETA01.txt
ECHO ----------------------
TYPE ISMETA02.txt

it seems to make sense in my head, I'll let you know what happens when I get a chance to put the code together.

aGerman
Expert
Posts: 4705
Joined: 22 Jan 2010 18:01
Location: Germany

Re: New to Forum - killing commands before default timeout

#4 Post by aGerman » 02 Nov 2011 14:39

Not exactly. Untested:

...

Code: Select all

>"%temp%\ismeta01.txt" 2>&1 START "" /B CMD /C QWINSTA /Server:ismeta01 %profile%

...

Code: Select all

:wait
TASKLIST /FI "IMAGENAME eq qwinsta.exe"|find /i "qwinsta.exe" >NUL &&GOTO wait

:results
TYPE "%temp%\ismeta01.txt"
DEL "%temp%\ismeta01.txt"
ECHO ----------------------

...

Regards
aGerman

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: New to Forum - killing commands before default timeout

#5 Post by Ed Dyreen » 02 Nov 2011 17:27

'
Are u saying QWINSTA will hang if the server is down ?, that's a bit weird.
You could also see if the server responds to ping before querying it, but that is not bulletproof as the server may still go down after the pong is received.

matt12582
Posts: 5
Joined: 02 Nov 2011 11:58

Re: New to Forum - killing commands before default timeout

#6 Post by matt12582 » 02 Nov 2011 23:55

not so much a hang, but the command will pause execution for 10-15 seconds while it waits to output that the RPC service is unavailable etc, before going on to my next GOTO

I redirected the command output to text files as aGerman had suggested, seems to be fairly quick offhand, as most of the servers return the command output immediately if they are responsive.

need to do some cleaning up though, the screen output is a little messy, but the concept seems to be there, offload to multiple threads instead of letting the batch call execute and kill tasks sequentially.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: New to Forum - killing commands before default timeout

#7 Post by Ed Dyreen » 03 Nov 2011 00:36

'
Good idea, I like multi-process solutions :)

Post Reply