1.

Solve : Assigning value to a variable.?

Answer»

Hi All,

Brains gone into netural with this (somewhat exhausted).

Trying to assign a value to a variable.

set /a xCount=netstat -an | find "%IB-IPPort-List%" | find /c /i "established"

Just doesn't want to work - how can I do this ?

Cheers (&stumped),
Cameronwell im no expert. but it looks like the seperators | is what is messing it up. the | is creating new line commands and skipping the user input.

TRY something along the lines of:
Code: [Select]set xCount1=netstat -an
set xCount2=find "%IB-IPPort-List%"
set xCount3=find /c /i "established"
set xcount=%xcount1% %xcount2% %xcount3%
set /p xcountmain=%xcount%
and once again, im no expert. but thats how i would see it happening
Thanks for the effort BatchFileBasics,

Unfortunately that idea doesn't work.

Cheers,
Cameronaw, dang.

well can i ask what the problem is when you try to run\execute the code?
paste the output pleaseHint:
Break your code up into smaller parts and use ECHO to show the current value of important variables.Thanks Geek - had tried that - but why does the pipe not work in the same way as the cmdline ?

Whiped up the following as alternate solution.

:::-----------------------------------------------------------------------------------
:::-- Checking Outbound Customer Links ...
:::-----------------------------------------------------------------------------------

netstat -an | find "10.223.26.20:85" > %xFile01%

For /F "tokens=1-6 delims=: " %%i in (%xFile01%) do call %0 CheckStatus %%j %%K %%n

goto :FinishRun

:::-----------------------------------------------------------------------------------
:::-- Call Functions ...
:::-----------------------------------------------------------------------------------

:CheckStatus

set yIP=%2
set yPort=%3
set yState=%4

::@echo ** IB - IP: %yIP% .. Port: %yPort% .. State: %yState% ..

IF "%yState%" EQU "ESTABLISHED" (
@echo ** IB - IP: %yIP% .. Port: %yPort% .. State: %yState% .. OK
) ELSE (
IF "%yState%" EQU "LISTENING" (
@echo ** IB - IP: %yIP% .. Port: %yPort% .. State: %yState% .. OK
) ELSE (
@echo ** IB - Check of IP: %%x from Customer - Not in Listening or Established State.
set MailSubject=Cal-Network Alert - Customer - Please INVESTIGATE.
set MailBody=`netstat -an | find "%yIP%:%yPort%"`
sendmail.vbs -f %MailFrom% -t %MAILTO% -s "%MailSubject%" -b "%MailBody%"
)
)

goto :EOFWho knows?
I have been using MS programs for years and I find that when you break things up into small chunks things start to work.
Moral: Function before Form
- OR -
Build the Barn this year,
Maybe paint it next year.lol Very good To get the output of a command into a variable, use FOR. Type FOR /? for examples and help.
You need a ^ before pipe.

Code: [Select]@echo off
set IB-IPPort-List=192.168.0.2
set xCount=netstat -an ^| find "%IB-IPPort-List%" ^| find /c /i "established"
echo "%xCount%"
pause
Hi Batcher - many thanks for the tip !!!

Never heard of the use.
Will give that a try in a test script.

Cheers,
CameronCode: [Select]for /f "tokens=*" %%a in ('netstat -an ^| find "%IB-IPPort-List%" ^| find /c /i "established"') do echo %%a
Indeed - that was my next step !!

See - there is a way to build the barn and paint it all in the same day



Discussion

No Comment Found