Request batch file help

Kruck

Distinguished
Sep 3, 2007
7
0
18,510
0
I'm trying to write a batch file that does a few simple(?) things. My fundamental goal is to open a command window, perform a netstat command, then use PAUSE to wait for any key, then run the netstat command again in the same command window. Repeatedly, until I close the window.

When I just used Netstat, the command window self-terminated, so I found
cmd /k netstat would keep it open. But that doesn't help, because it only runs once.

So I tried a loop, and so far my syntax has been unsuccessful, I think because I need to use the cmd /k the first time, and a plain netstat command the second time... but I can't figure out how to get the batch file to insert additional netstat commands in the same command window.

Something like:
cmd /k netstat
PAUSE
:numbers
netstat
PAUSE
goto :numbers

but again, the subsequent netstat commands don't show when I hit a key and the command window is active.

Also, I'm not at that point yet, but I'm hoping this will remain linked to the command window; I will be bouncing to another program to perform activities, then will want to continually bounce back to the command window to check the IP address list.

Can anyone give a hand?
Thanks!

 

Kruck

Distinguished
Sep 3, 2007
7
0
18,510
0
the thing that has me stuck is pushing the second netstat to the command window; if I just use the cmd /k then it opens a new window each time, which isn't what I want- once that command window is open, how do I make that netstat 10 active?

cmd /k netstat
netstat 10

doesn't refresh the netstat every 10 seconds, it just does it once :(

Thanks!
 

Kruck

Distinguished
Sep 3, 2007
7
0
18,510
0
awesome, that worked; can I ask for one more piece of advice?

To narrow down what gets returned, I want to look for only IP addresses that include a specific number. I can do this with the hand-entered command
netstat -n | find "4000"

trying to figure out the syntax for those double quotes is killing me; I've tried things like
cmd/k "netstat -n | find """4000""" 10"
and
cmd/k "netstat -n | find " & chr(34) & "4000" & chr(34) & " 10"
cmd/k "netstat -n | find " & chr(34) & """4000""" & chr(34) & " 10"
cmd/k "netstat -n | find " & """ & "4000" & """ & " 10"

but nothing seems to work.

Many thanks!
 

Kruck

Distinguished
Sep 3, 2007
7
0
18,510
0

Thanks iJack, that got me sooo close I was able to finish it off by trial and error; here is the final version I used:

cmd /s /k "netstat -n 5 | find "4000""

Marking you answer as correct :)

Thanks,
kruck
 
Thread starter Similar threads Forum Replies Date
S Apps General Discussion 4
D Apps General Discussion 2
AndrewFreedman Apps General Discussion 0
N Apps General Discussion 1
NoctisLionward Apps General Discussion 2
malavena Apps General Discussion 3
Tom Waller Apps General Discussion 2
P Apps General Discussion 1
S Apps General Discussion 4
F Apps General Discussion 1
euphoria4949 Apps General Discussion 1
A Apps General Discussion 1
G Apps General Discussion 0
G Apps General Discussion 0
dannyboy2233 Apps General Discussion 2
M Apps General Discussion 4
MajinCry Apps General Discussion 4
M Apps General Discussion 1
D Apps General Discussion 2
G Apps General Discussion 1

Similar threads


ASK THE COMMUNITY