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
New to Forum - killing commands before default timeout
Moderator: DosItHelp
Re: New to Forum - killing commands before default timeout
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
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
Re: New to Forum - killing commands before default timeout
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.
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.
Re: New to Forum - killing commands before default timeout
Not exactly. Untested:
...
...
...
Regards
aGerman
...
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
Re: New to Forum - killing commands before default timeout
'
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.
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.
Re: New to Forum - killing commands before default timeout
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.
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.
Re: New to Forum - killing commands before default timeout
'
Good idea, I like multi-process solutions
Good idea, I like multi-process solutions
