• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 443
  • Last Modified:

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.
0
Gonzalo Becerra
Asked:
Gonzalo Becerra
  • 5
  • 4
2 Solutions
 
vikas_madhusudanaCommented:
just add a if condition

if %name% == "Task ZipIISLogs" (
echo Task Name=%name%, Task Result=%result%
if not %result%==0 (
echo Task %name% failed
)
)
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
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

0
 
vikas_madhusudanaCommented:
sorry change the if condition to

if %name% == "ZipIISLogs"  (
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
vikas_madhusudanaCommented:
if this doesnt work try

if %name% == ZipIISLogs  (
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
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

0
 
vikas_madhusudanaCommented:
did you try this

if %name% == ZipIISLogs  (

ie remove the double coutes " "
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
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

0
 
vikas_madhusudanaCommented:
what are you expecting then

if you are expecting only

Task ZipIISLogs failed

remove the line

echo Task Name=%name%, Task Result=%result%
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
i need only see when faild the task.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now