Gonzalo Becerra
asked on
Monitoring Scheduled Task
Hi :)
I need help with any script to monitoring Scheduled Task, i found this scripts but only i need monitor only one task:
Script:
@echo off
for /F "delims=" %%a in ('schtasks /query /v /fo:list ^| findstr /i
"Taskname Result"') do call :Sub %%a
goto :eof
:Sub
set Line=%*
set BOL=%Line:~0,4%
set MOL=%Line:~38%
if /i %BOL%==Task (
set name=%MOL%
goto :eof
)
set result=%MOL%
echo Task Name=%name%, Task Result=%result%
if not %result%==0 (
echo Task %name% failed
)
Result:
Task Name=backup, Task Result=-2
Task backup failed
Task Name=BackupSPS, Task Result=0
Task Name=BackupWSS, Task Result=0
Task Name=BackupWSS2, Task Result=0
Task Name=BackupWSS3, Task Result=0
Task Name=FDMigrateTool, Task Result=0
Task Name=iisreset, Task Result=0
Task Name=ZipIISLogs, Task Result=1
Task ZipIISLogs failed
expected result:
Task ZipIISLogs failed
And when i finish where can i add a line to send mail via blat.
I need help with any script to monitoring Scheduled Task, i found this scripts but only i need monitor only one task:
Script:
@echo off
for /F "delims=" %%a in ('schtasks /query /v /fo:list ^| findstr /i
"Taskname Result"') do call :Sub %%a
goto :eof
:Sub
set Line=%*
set BOL=%Line:~0,4%
set MOL=%Line:~38%
if /i %BOL%==Task (
set name=%MOL%
goto :eof
)
set result=%MOL%
echo Task Name=%name%, Task Result=%result%
if not %result%==0 (
echo Task %name% failed
)
Result:
Task Name=backup, Task Result=-2
Task backup failed
Task Name=BackupSPS, Task Result=0
Task Name=BackupWSS, Task Result=0
Task Name=BackupWSS2, Task Result=0
Task Name=BackupWSS3, Task Result=0
Task Name=FDMigrateTool, Task Result=0
Task Name=iisreset, Task Result=0
Task Name=ZipIISLogs, Task Result=1
Task ZipIISLogs failed
expected result:
Task ZipIISLogs failed
And when i finish where can i add a line to send mail via blat.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry change the if condition to
if %name% == "ZipIISLogs" (
if %name% == "ZipIISLogs" (
if this doesnt work try
if %name% == ZipIISLogs (
if %name% == ZipIISLogs (
ASKER
Sorry but now i don't see result, the script is fine?
@echo off
for /F "delims=" %%a in ('schtasks /query /v /fo:list ^| findstr /i
"Taskname Result"') do call :Sub %%a
goto :eof
:Sub
set Line=%*
set BOL=%Line:~0,4%
set MOL=%Line:~38%
if /i %BOL%==Task (
set name=%MOL%
goto :eof
)
set result=%MOL%
if %name% == "backup" (
echo Task Name=%name%, Task Result=%result%
if not %result%==0 (
echo Task %name% failed
)
)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Now i can see, but the result is not ok because:
Result:
Task Name=ZipIISLogs , Task Result=1
Task ZipIISLogs failed
Result:
Task Name=ZipIISLogs , Task Result=1
Task ZipIISLogs failed
@echo off
for /F "delims=" %%a in ('schtasks /query /v /fo:list ^| findstr /i
"Taskname Result"') do call :Sub %%a
goto :eof
:Sub
set Line=%*
set BOL=%Line:~0,4%
set MOL=%Line:~38%
if /i %BOL%==Task (
set name=%MOL%
goto :eof
)
set result=%MOL%
if %name% == ZipIISLogs (
echo Task Name=%name%, Task Result=%result%
if not %result%==0 (
echo Task %name% failed
)
)
what are you expecting then
if you are expecting only
Task ZipIISLogs failed
remove the line
echo Task Name=%name%, Task Result=%result%
if you are expecting only
Task ZipIISLogs failed
remove the line
echo Task Name=%name%, Task Result=%result%
ASKER
i need only see when faild the task.
ASKER
In Result i see all with this condition:
Task Name=backup, Task Result=-2
Task Name=BackupSPS, Task Result=0
Task Name=BackupWSS, Task Result=0
Task Name=BackupWSS2, Task Result=0
Task Name=BackupWSS3, Task Result=0
Task Name=FDMigrateTool, Task Result=0
Task Name=iisreset, Task Result=0
Task Name=ZipIISLogs, Task Result=1
Open in new window