Page 1 of 1

Batch code missing comparisson

Posted: 20 Oct 2011 07:22
by hunterhhh
Forum members;

I'm facing an error that it seems to be a logic error (from myself) or lack of knowledge in regards Batch scripting (I've always been Unix guy), so hope someone could give me some light on this.

I'm setting a monitor (not exactly, because is reactive) process on a VM - Win2003 pro, for corrective purposes of Tomcat process, itself only monitors the established connnections within server and users, and if it finds more than 80 established connections, will store that first violation, and wait for certain time to run again, if it finds more than 80 connections 3 consecutive times, then will stop Tomcat Server and start up again the processes.

So far I've the structure of the code but I'm finding a couple of issues that kept me hitting my head against the keyboard.

1.- In the monitor log, If I found more than 80 open connections at that time I send an ECHO 1 >>"C:\Somedirectory\Sompepath\openconnections.log", but when I check the log file found that it writes "1 " (the 1 and a blank space after and a return); is there a way to only write the file with a flat '1' with no extra characters?

2.- Once the file is created the program will read the information and assign that to a variable:

SET /P mycounter =<"C:\Somedirectory\Sompepath\openconnections.log"

I placed a ECHO output for that and I'm seeing that is getting the information as expected "1 ", and then

3.- I peform the validation against my flag to stop tomcat servies

IF [%mycounter%] EQU [%maxtries%] CALL rebootscript.bat

However, the validation is always true, an ECHO output for this last code line showed me [1 ] EQU [111]; my understanding is that I'm doing a string to string comparisson, but i can't figure out why DOS is assuming that 1 is the same as 111 not the same string lenght, neither value..., I'm pretty sure I'm missing something here, but can't figure out what is that small piece I'm doing wrong.

Cheers.

~Hunter

Re: Batch code missing comparisson

Posted: 20 Oct 2011 13:03
by trebor68
You have input the code:

Code: Select all

echo 1 >>file.txt

With a space after the number 1.

If you don't want the space please use this code:

Code: Select all

echo 1>>file.txt

Re: Batch code missing comparisson

Posted: 28 Oct 2011 10:42
by aGerman
I strictly recomment the opposite style for echo redirections:

Code: Select all

>>"file.txt" echo 1

Regards
aGerman