for sorting

L

Larry

I am writing a script using the 'for' command that should list a line in the
output of a command. However it seems to hang. The syntax below is what I
have come up with. What I want to do is use the file cls.txt to house my
clustered server names and feed that to the uptime utility. Then scan the
output of that for a certain line of text (cluster availability). Could
someone offer me some advise on my syntax, this thing hangs up...

for /f %%a in (cls.txt) do (
uptime %%a /p:30 /v
findstr /i /c:"cluster availability"
)

Thank you, Larry
 
J

Jerold Schulman

I am writing a script using the 'for' command that should list a line in the
output of a command. However it seems to hang. The syntax below is what I
have come up with. What I want to do is use the file cls.txt to house my
clustered server names and feed that to the uptime utility. Then scan the
output of that for a certain line of text (cluster availability). Could
someone offer me some advise on my syntax, this thing hangs up...

for /f %%a in (cls.txt) do (
uptime %%a /p:30 /v
findstr /i /c:"cluster availability"
)

Thank you, Larry

for /f %%a in (cls.txt) do (
for /f %%b in ('uptime %%a /p:30 /v^|Findstr /i /c:"cluster availability"') do (
@echo %%b
)
)


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
L

Larry

Thank you Jerold, I appreciate your input. They output that I am looking for
from a single command is:

uptime myserver | findstr /i /c:"statistics for
cluster"
/i /c:"cluster availability"
Statistics for Cluster Node: server1
Statistics for Cluster Node: server2
Availability Statistics for Cluster: myserver
Cluster Availability: 99.8470%

I guess I get confused with the multiple (command (command etc....)

thank you, Larry

 
J

Jerold Schulman

Since I don't have a cluster, I am not sure what you are asking.


Thank you Jerold, I appreciate your input. They output that I am looking for
from a single command is:

uptime myserver | findstr /i /c:"statistics for
cluster"
/i /c:"cluster availability"
Statistics for Cluster Node: server1
Statistics for Cluster Node: server2
Availability Statistics for Cluster: myserver
Cluster Availability: 99.8470%

I guess I get confused with the multiple (command (command etc....)

thank you, Larry



Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
L

Larry

If I just run this from the command prompt (without using for) I get the
following output:

The command:

uptime myserver | findstr /i /c:"uptime report" /c:"syst
em avai" /c:"total uptime"

The output:
Uptime Report for: \\aserver
System Availability: 99.8303%
Total Uptime: 453d 3h:26m:57s


If I use the 'for' command to loop thru a server list, the output comes
out like:

Type at the command prompt:

for /f %a in (cls.txt) do (for /f %b in ('uptime %a ^| fi
ndstr /i /c:"uptime report" /c:"system avai" /c:"total uptime"') do
(@echo %b ))

The output:

for /F %b in ('uptime fzrvew02m | findstr /i /c:"uptime
report" /c:"system avai" /c:"total uptime"') do () )

C:\appdev\ClusterAvail>()
Uptime

C:\appdev\ClusterAvail>()
System

C:\appdev\ClusterAvail>()
Total

Can anyone tell me what I've missed?

Thank you....
 
M

Matthias Tacke

Larry said:
If I just run this from the command prompt (without using for) I get
the >following output:

The command:

uptime myserver | findstr /i /c:"uptime report" /c:"syst
em avai" /c:"total uptime"

The output:
Uptime Report for: \\aserver
System Availability: 99.8303%
Total Uptime: 453d 3h:26m:57s
Can anyone tell me what I've missed?

Thank you....

Yes, you missed at all to tell us what you want to achieve with your
batch.
- extract the percentage / Uptime ?
- to a file / var ?

See the for /f options in the help "skip=1 tokens=2 delims=:"

for /?

HTH
 
L

Larry

Matthias, the output from this uptime command can be quite large. What I
want are a few lines from this output that contain:

Uptime Report for: \\aserver
System Availability: 99.8303%
Total Uptime: 453d 3h:26m:57s

the above information is 3 lines of probably 20. What I need to do is
extract these 3 lines and remove that space so they line up (that would be
nice, however not really important). Some of my problem (other than being an
amatuer at this) is I want to feed more than one command to 'FOR' after the
'DO' command. I get lost when I need to do something for ex. for /f % a in
(myfile.txt) do uptime myserver | findstr /i "stuff", actually I am not sure
where to put the (command(another command) etc. Then I would like to push
this output to a file that I can use blat to email to myself.

I have a list of servers that I need to feed to the FOR command as well.
Which would probably look something like:


for /f %a in (server.dat) do uptime %a | findstr /i /c:"info" /c:"moreinfo"
/c:"somemoreinfo" > outfile.dat



Larry
 
J

Jerold Schulman

@echo off
setlocal
if exist outfile.dat del /q outfile.dat
for /f "Tokens=*" %%a in (server.dat) do (
for /f "Tokens=*" %%b in ('uptime %%a') do (
set line=%%b
call :parse
)
)
blat .........................
del /q outfile.dat
endlocal
goto :EOF
:parse
if /i "%line:~0,18%" EQU "Uptime Report for:" goto output
if /i %"line:~0,19%" EQU "System Availability:" goto output
if /i %"line:~0,13%" EQU "Total Uptime:" goto output
goto :EOF
:blush:utput
@echo %line%>>outfile.dat

Matthias, the output from this uptime command can be quite large. What I
want are a few lines from this output that contain:

Uptime Report for: \\aserver
System Availability: 99.8303%
Total Uptime: 453d 3h:26m:57s

the above information is 3 lines of probably 20. What I need to do is
extract these 3 lines and remove that space so they line up (that would be
nice, however not really important). Some of my problem (other than being an
amatuer at this) is I want to feed more than one command to 'FOR' after the
'DO' command. I get lost when I need to do something for ex. for /f % a in
(myfile.txt) do uptime myserver | findstr /i "stuff", actually I am not sure
where to put the (command(another command) etc. Then I would like to push
this output to a file that I can use blat to email to myself.

I have a list of servers that I need to feed to the FOR command as well.
Which would probably look something like:


for /f %a in (server.dat) do uptime %a | findstr /i /c:"info" /c:"moreinfo"
/c:"somemoreinfo" > outfile.dat



Larry


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
M

Matthias Tacke

Jerold said:
@echo off
setlocal
if exist outfile.dat del /q outfile.dat
for /f "Tokens=*" %%a in (server.dat) do (
for /f "Tokens=*" %%b in ('uptime %%a') do (
set line=%%b
call :parse
)
)
blat .........................
del /q outfile.dat
endlocal
goto :EOF
:parse
if /i "%line:~0,18%" EQU "Uptime Report for:" goto output
if /i %"line:~0,19%" EQU "System Availability:" goto output
if /i %"line:~0,13%" EQU "Total Uptime:" goto output
goto :EOF
:blush:utput
@echo %line%>>outfile.dat
Hello Jerold,
I'm not shure if the positional comparisons work due to indentations.

@larry here's my solution

Findstr supports multiple searchstrings in a file see findstr /?

I tested the following batch partially based on a previous thread with
uptime.
http://groups.google.com/[email protected]

::UpTimeReport.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal

:: Set Output to same Drive:path\Name as this batch with extension rep
set RepFile=%~dpn0.rep
if exist %RepFile% Del /Q %RepFile%

:: setup file with keywords for findstr /G option
set Keywords=%temp%\Uptime.key
%KeyWords% Echo Uptime Report for:

:: loop though servers and then filter on keywords
for /f %%a in (server.dat) do (
for /f "tokens=*" %%b in (
'uptime %%a /p:30 /v ^|Findstr /I /G:%KeyWords%') do (
Call :Strip %%b
)
)
::blat
del /Q %KeyWords% %RepFile%
goto :eof
:: Words in %%b are treated as arguments spaces reduced to one
:Strip::UpTimeReport.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::

HTH
 
J

Jerold Schulman

It works because the FOR command removes leading spaces.

Hello Jerold,
I'm not shure if the positional comparisons work due to indentations.

@Larry here's my solution

Findstr supports multiple searchstrings in a file see findstr /?

I tested the following batch partially based on a previous thread with
uptime.
http://groups.google.com/[email protected]

::UpTimeReport.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal

:: Set Output to same Drive:path\Name as this batch with extension rep
set RepFile=%~dpn0.rep
if exist %RepFile% Del /Q %RepFile%

:: setup file with keywords for findstr /G option
set Keywords=%temp%\Uptime.key

:: loop though servers and then filter on keywords
for /f %%a in (server.dat) do (
for /f "tokens=*" %%b in (
'uptime %%a /p:30 /v ^|Findstr /I /G:%KeyWords%') do (
Call :Strip %%b
)
)
::blat
del /Q %KeyWords% %RepFile%
goto :eof
:: Words in %%b are treated as arguments spaces reduced to one
:Strip
::UpTimeReport.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::

HTH


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
M

Matthias Tacke

Jerold said:
It works because the FOR command removes leading spaces.

Yes, of course, thanks for the hint.

I stuck with a "delims=:" in mind to get only the value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top