Hi All,
I have written if condition for my requirement but it is not working please assist me.
FOR /f "tokens=4*" %%a in (pcheck.txt) do
( set var = %%a)
IF %var% == "LISTENING"
echo Ecm is still running
else echo "Sending alarm"
I am getting following error:
The syntax of the command is incorrect.
thanks,
JP
If condition issue
Moderator: DosItHelp
Re: If condition issue
hi redro,
This can't work, because a block has to begin at the same line (look at if /?)
The second problem is your compare %var%=="LISTENING", batch isn't a "normal" language with strings, variables and so.
It only expands something. So you will get(in the best case).
You can try this
jeb
redro wrote:FOR /f "tokens=4*" %%a in (pcheck.txt) do
( set var = %%a)
IF %var% == "LISTENING"
echo Ecm is still running
else echo "Sending alarm"
This can't work, because a block has to begin at the same line (look at if /?)
The second problem is your compare %var%=="LISTENING", batch isn't a "normal" language with strings, variables and so.
It only expands something. So you will get(in the best case).
Code: Select all
if Listening == "LISTENING"
You can try this
Code: Select all
setlocal
set var=empty
FOR /f "tokens=4*" %%a in (pcheck.txt) do (
set var = %%a
)
IF "%var%"=="LISTENING" (
echo Ecm is still running
) else (
echo "Sending alarm"
)
jeb
Re: If condition issue
hi jeb,
i have modified my code with your suggestions but i am getting else condition. In my case server is running fine.
so we have to get server is running.
Please assist me.
Thanks,
JP
i have modified my code with your suggestions but i am getting else condition. In my case server is running fine.
so we have to get server is running.
Please assist me.
Thanks,
JP
Re: If condition issue
hi redo,
try to use some debugging code, to see what you read.
hope it helps
jeb
try to use some debugging code, to see what you read.
Code: Select all
setlocal
set var=empty
FOR /f "tokens=4*" %%a in (pcheck.txt) do (
set var = %%a
echo read "%%a"
)
echo Comparing "%var%" with "LISTENING"
IF "%var%"=="LISTENING" (
echo Ecm is still running
) else (
echo "Sending alarm"
)
hope it helps
jeb
Re: If condition issue
Hi Jeb,
It is taking only empty value and passing condition two.
FYI,...
pcheck.txt consists of the following data, from that i am getting LISTENING word. If LISTENING is exists then the server is running else down then i have to soot a mail.
TCP 0.0.0.0:9095 0.0.0.0:0 LISTENING
Please assist me.
Thanks,
JP
It is taking only empty value and passing condition two.
FYI,...
pcheck.txt consists of the following data, from that i am getting LISTENING word. If LISTENING is exists then the server is running else down then i have to soot a mail.
TCP 0.0.0.0:9095 0.0.0.0:0 LISTENING
Please assist me.
Thanks,
JP
Re: If condition issue
and the next round begin
are different things, (first the name of the variable is "var" in the second case it is "var " (with one space).
so your code should look like
Code: Select all
set var=%%
and
set var = %%a
are different things, (first the name of the variable is "var" in the second case it is "var " (with one space).
so your code should look like
Code: Select all
@echo off
setlocal
set var=empty
FOR /f "tokens=4*" %%a in (pcheck.txt) do (
set var=%%a
echo read "%%a"
)
echo Comparing "%var%" with "LISTENING"
IF "%var%"=="LISTENING" (
echo Ecm is still running
) else (
echo "Sending alarm"
)
Re: If condition issue
Hi Jeb
Sounds good , it is working.
Could you please assist me in "sending mail please i have to add the bellow code
@echo off & setlocal
:: set the temp file location
set tempmail=%temp%\tempmail.%random%.txt
:: echo the basic headers to the temp file
echo To: "Scripting Test" ^<praveen.pullela@sirvisetti.com^>, ^<prakash.redrouthu@sirvisetti.com^> > %tempmail%
echo From: "Me" ^<support@sirvisetti.com^> >> %tempmail%
echo Subject: CVG ESB Process DOWN >> %tempmail%
:: echo the blank line that separates the header from the body text
echo.>>%tempmail%
:: echo the body text to the temp file
echo ESB DOWN ON 9099 port PLS check>> %tempmail%
echo GOOD DAY.>> %tempmail%
:: move the temp file to the mail pickup directory
:: adjust this location for your system
move %tempmail% c:\inetpub\mailroot\pickup
set tempmail=
endlocal
Please suggest me how to handle this.
Thanks,
JP
Sounds good , it is working.
Could you please assist me in "sending mail please i have to add the bellow code
@echo off & setlocal
:: set the temp file location
set tempmail=%temp%\tempmail.%random%.txt
:: echo the basic headers to the temp file
echo To: "Scripting Test" ^<praveen.pullela@sirvisetti.com^>, ^<prakash.redrouthu@sirvisetti.com^> > %tempmail%
echo From: "Me" ^<support@sirvisetti.com^> >> %tempmail%
echo Subject: CVG ESB Process DOWN >> %tempmail%
:: echo the blank line that separates the header from the body text
echo.>>%tempmail%
:: echo the body text to the temp file
echo ESB DOWN ON 9099 port PLS check>> %tempmail%
echo GOOD DAY.>> %tempmail%
:: move the temp file to the mail pickup directory
:: adjust this location for your system
move %tempmail% c:\inetpub\mailroot\pickup
set tempmail=
endlocal
Please suggest me how to handle this.
Thanks,
JP
Re: If condition issue
Hi Jeb,
Now i am able to send mail if process is not running. how i have to make it as automate this script for when ever the server down then this script should be through the mail. and right now i am checking for one port with the command as
@ netstat -an |find /i "9095" >pcheck.txt
but actually i have to check 3 processes are running are not. Please don't hesitate me to assist.
Thanks,
JP
Now i am able to send mail if process is not running. how i have to make it as automate this script for when ever the server down then this script should be through the mail. and right now i am checking for one port with the command as
@ netstat -an |find /i "9095" >pcheck.txt
but actually i have to check 3 processes are running are not. Please don't hesitate me to assist.
Thanks,
JP