but the number of entries is different per system. I have to try to get this working
in a bit less than a week, or I'll have to spend hours manually going through a
process that shouldn't be manual.
Sample baseline:
Code: Select all
cd c:\rundir
del oldlog.txt
pq.exe -n 192.168.20.12 -e 1234 -p TCP > oldlog.txt
pq.exe -n 192.168.20.13 -e 1234 -p TCP >> oldlog.txt
pq.exe -n 192.168.20.14 -e 1234,1235,1236 -p TCP >> oldlog.txt
pq.exe -n 192.168.20.15 -e 1234,1236 -p TCP >> oldlog.txt
---------------------------------
So basically, -n is an ip address. -e may have several 3 or 4 digit port numbers, at least one, but as many as three.
This script gets the baseline data. I need to modify it so each of the different server lines (with the IPs)
sends their output to a different file (ideally %IP_ADDRESS%.txt). AND here comes the fun part. Due to the
scripts being different on each system, and the fact that there are 3 or 4 other scripts that end up calling
this one, I need to pull the relevant lines (pq.exe) from the baseline script , extract the host IP and the ports,
and use that to send data for comparison to output files like %sSERVER_IP%.txt
I've spent quite a few hours communing with Prof Google on this, but it's been 20 years since I worked with
dos/cmd batch files. I'm also confirming my theory that code/technical data found via professor google is only as
good as the keyboard kommando typing it, and many people think they're experts but they aren't, which is why I'm here.
Since I havent had any luck setting variables in a for loops because I dont yet fully understand delayed expansion,
I'm trying a label/function call in my script. Here's an example of how I'd LIKE it to work:
-----------------------
Code: Select all
@echo off
setlocal
REM pull the strings from the legacy bat to get IPs and ports
for /f "USEBACKQ tokens=* delims= " %%i in (`findstr pq.exe getport.bat`) do (
call :runit
)
:runit
REM Set server variable to the IP address
set server=%3
REM set ports variable to all of the space-delimitted entries after -e (but it's not working).
set ports=%5
pq.exe -n %server% -e %ports% -p TCP >> %server%.txt
REM AFTER THIS PART I GO TO PARSE THE OUTPUT
-------------------------------------------------
Another method would be to set the variables in the for loops, which I cant get to work.
Code: Select all
for /f "USEBACKQ tokens=* delims= " %%i in (`findstr pq.exe getport.bat`) do (
for /f "USEBACKQ tokens=3 delims= " %%s in (`echo %%i`) do set server=%s
for /f "USEBACKQ tokens=5 delims= " %%p in (`echo %%i`) do set ports=%p
call :runit
)
:runit
pq.exe -n %server% -e %ports% -p TCP >> %server%.txt
--------------------------
On the occasions where I have been able to get variables set, the port variable only takes the first
entry, stopping at the comma delimitter. Despite the many hours I've spent so far, I haven't figured
out the delayed expansion. I've been on a completely different OS for quite a while, so I've forgotten
what I used to know about batch programming.
OK so. Assuming anyone has made it this far, I'm hoping I can get some input on how to set the variables
needed so I can get runit to work.
Any help would be greatly appreciated (NOTE: I am not liable for physical injuries due to excessive
laughter caused by my crapplication coding.)