Link to home
Start Free TrialLog in
Avatar of Gonzalo Becerra
Gonzalo BecerraFlag for Argentina

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.
ASKER CERTIFIED SOLUTION
Avatar of vikas_madhusudana
vikas_madhusudana
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gonzalo Becerra

ASKER

its ok?

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


@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 %name% == "Task ZipIISLogs" (
echo Task Name=%name%, Task Result=%result%
if not %result%==0 (
echo Task %name% failed
)
)

Open in new window

sorry change the if condition to

if %name% == "ZipIISLogs"  (
if this doesnt work try

if %name% == ZipIISLogs  (
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
)
)

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Now i can see, but the result is not ok because:

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 
) 
)

Open in new window

what are you expecting then

if you are expecting only

Task ZipIISLogs failed

remove the line

echo Task Name=%name%, Task Result=%result%
i need only see when faild the task.