typeperf commands in batch script issue
Posted: 29 Apr 2014 10:35
Hi,
Appreciate any help with below script.
@echo off
setlocal enabledelayedexpansion
set time_interval=%1
set iteration_set=
:logMemCpuUsage
if "!iteration_set!" EQU "1" (
echo inside if
for /f "skip=1 tokens=* delims=EOL" %%a in ('typeperf "\Processor(_Total)\%% Processor Time" -SC 1 -y') do echo samba:%%a
for /f "skip=1 tokens=* delims=EOL" %%i in ('typeperf "\Memory\Available MBytes" -SC 1 -y') do echo siva:%%i
) else (
echo inside else
typeperf "\processor(_Total)\%% Processor Time" -SC 1 -y
typeperf "\Memory\Available MBytes" -SC 1 -y
set iteration_set=1
)
timeout /t %time_interval% /nobreak >nul
goto :logMemCpuUsage
1)Actual requirement is to log the CPU usage and Available RAM at every inputted interval of seconds.
2)When I execute the typeperf for processor Time out side the for loop it prints the output properly.
C:\>typeperf "\Processor(_Total)\% Processor Time" -SC 1 -y
"(PDH-CSV 4.0)","\\SBATTAGI-LAP\Processor(_Total)\% Processor Time"
"04/29/2014 21:57:12.660","9.909430"
The command completed successfully.
C:\>
But I wanted to log the first line of this output only for the time and subsequently log only second line (to a csv file) and ignore the last line which says "The command completed successfully" as well.
For this I added a if condition and inside that I am running processor time command using for statement and skipping the first line.
Surprisingly the output inside the for statement is still having the first line and also it has extra lines of output which was not there when I run the same command outside of for statement.
The output I am getting is:
--------------------------
C:\>C:\MemCpuUsage.cmd 5
inside else
"(PDH-CSV 4.0)","\\SBATTAGI-LAP\processor(_Total)\% Processor Time"
"04/29/2014 22:02:59.470","7.179410"
The command completed successfully.
"(PDH-CSV 4.0)","\\SBATTAGI-LAP\Memory\Available MBytes"
"04/29/2014 22:03:00.880","4904.000000"
The command completed successfully.
inside if
samba:"(PDH-CSV 4.0)","\\SBATTAGI-LAP\Processor(_Total)\% Processor Time"
samba:"04/29/2014 22:03:06.560","9.519420"
samba:xiting, please wait...
samba:The command completed successfully.
siva:"(PDH-CSV 4.0)","\\SBATTAGI-LAP\Memory\Available MBytes"
siva:"04/29/2014 22:03:08.030","4900.000000"
siva:xiting, please wait...
siva:The command completed successfully.
siva:
Terminate batch job (Y/N)? y
C:\>
Please help me to resolve this issue.
I need to skip the first,last line in the ouput and also the extra line of output "xiting, please wait..."
Thanks
Sambasiva
Appreciate any help with below script.
@echo off
setlocal enabledelayedexpansion
set time_interval=%1
set iteration_set=
:logMemCpuUsage
if "!iteration_set!" EQU "1" (
echo inside if
for /f "skip=1 tokens=* delims=EOL" %%a in ('typeperf "\Processor(_Total)\%% Processor Time" -SC 1 -y') do echo samba:%%a
for /f "skip=1 tokens=* delims=EOL" %%i in ('typeperf "\Memory\Available MBytes" -SC 1 -y') do echo siva:%%i
) else (
echo inside else
typeperf "\processor(_Total)\%% Processor Time" -SC 1 -y
typeperf "\Memory\Available MBytes" -SC 1 -y
set iteration_set=1
)
timeout /t %time_interval% /nobreak >nul
goto :logMemCpuUsage
1)Actual requirement is to log the CPU usage and Available RAM at every inputted interval of seconds.
2)When I execute the typeperf for processor Time out side the for loop it prints the output properly.
C:\>typeperf "\Processor(_Total)\% Processor Time" -SC 1 -y
"(PDH-CSV 4.0)","\\SBATTAGI-LAP\Processor(_Total)\% Processor Time"
"04/29/2014 21:57:12.660","9.909430"
The command completed successfully.
C:\>
But I wanted to log the first line of this output only for the time and subsequently log only second line (to a csv file) and ignore the last line which says "The command completed successfully" as well.
For this I added a if condition and inside that I am running processor time command using for statement and skipping the first line.
Surprisingly the output inside the for statement is still having the first line and also it has extra lines of output which was not there when I run the same command outside of for statement.
The output I am getting is:
--------------------------
C:\>C:\MemCpuUsage.cmd 5
inside else
"(PDH-CSV 4.0)","\\SBATTAGI-LAP\processor(_Total)\% Processor Time"
"04/29/2014 22:02:59.470","7.179410"
The command completed successfully.
"(PDH-CSV 4.0)","\\SBATTAGI-LAP\Memory\Available MBytes"
"04/29/2014 22:03:00.880","4904.000000"
The command completed successfully.
inside if
samba:"(PDH-CSV 4.0)","\\SBATTAGI-LAP\Processor(_Total)\% Processor Time"
samba:"04/29/2014 22:03:06.560","9.519420"
samba:xiting, please wait...
samba:The command completed successfully.
siva:"(PDH-CSV 4.0)","\\SBATTAGI-LAP\Memory\Available MBytes"
siva:"04/29/2014 22:03:08.030","4900.000000"
siva:xiting, please wait...
siva:The command completed successfully.
siva:
Terminate batch job (Y/N)? y
C:\>
Please help me to resolve this issue.
I need to skip the first,last line in the ouput and also the extra line of output "xiting, please wait..."
Thanks
Sambasiva