Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
can any clear me that what the difference b/w
%%g and %g% in batch filemeans
if %%g==10.10.10.10or
if %g%==10.10.10.10

Some of this information is specific to win nt or higher, but some applies right back to dos:
%%g is a for loop variable only valid inside a for loop, as the for loop iterates over it's set the variable will change accordingly. When the for loop is finished the variable becomes undefined. Also not that in for loop variable are case sensitive and are normally explicitly defined with the exception of a for /f loop where some variables can be implicitly defined.
%g% in an environment variable and can be set using the set command alone, but the /p or /a switches can be present to modify set's behavior. Environment variables set at the command line or is batch file should stay present until the instance of the command processor that created it is closed unless the setlocal command, or one of it's variants, is used. In such a case the variables with either be cleared or restored after the endlocal command. System wide variables are store in the registry and can only be set with utilities, the windows gui or by editing the registry.

Thanks A Lot for reply
will you plz help me out for below script
i have prepare a batch script for pinging my all devices.
(in my "ping" file 2 IP is there 10.10.10.10 & 10.10.10.9)for /f %%I in (ping) do (ping -n 1 %%I | find "Reply" >> nul
if errorlevel 1 echo %%I wan IP was Down >> logfail)
for /f "tokens=1 delims= " %%g in (logfail) do (
if %%g==10.10.10.10 echo FM02 server is down %time% >> logosspingfailthe output for this script is FM02 server is down,
i want that condition compares two IP 10.10.10.10 and 10.10.10.9 if any one or both IP is not pinging it should show echo ""character"" means
if%%g==10.10.10.10 or %%g==10.10.10.9 echo FM02 server is down.(on applying if condition in 2 lines it showing the message for 2 times that i don't want)
Kindly help me to do so

I'm not sure if I follow you correctly, what the below should
do is echo "FM02 server is down %time%" into "logosspingfail"
if either of the addresses fail to reply, but only once if
both of them are inactive.for /f %%I in (ping) do ( ping -n 1 %%I | > nul find "Reply" || ( >> logosspingfail ECHO FM02 server is down %time% GOTO BREAKLOOP ) ) :BREAKLOOP

Actually the ping operation is one part of the script, and comparing it with the exact IP and than write the particular character is other.
:start
for /f %%I in (ping) do (ping -n 1 %%I | find "Reply" >> nul
if errorlevel 1 echo %%I wan IP was Down >> logfail)
for /f "tokens=1 delims= " %%g in (logfail) do (
if %%g==10.10.10.10 echo FM02 server is down >> logosspingfail
if %%g==1.1.1.1 echo FM01 server is down >> logosspingfail )@echo off > displayping.html
for /f "tokens=1 delims= " %%g in (logosspingfail) do @ECHO %%g >> displayping.html
goto start
so this is the example what i want,i am having more that 250 IP so to remember ip on display is typical task, i.e. i want to compare it with ""if "" and than display the character only.
the Problem is - " one device is having 2 IP i want that if any of the IP is down it should display message, both IP down the same message should display."
i think now you are getting me wat exactly i want.
Hope for your response.
thanks for the earlier response
:kuril

![]() |
Assign Memory Stick Drive...
|
forgot password for a Win...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |