N
Natxo Asenjo
hi,
I need to check the status of some schedule tasks in a windows server. At
my $JOB we use nagios, so I thouth, let's write a plugin (I could not
find anything at the nagiosexchange).
windows 2k3 has a command schtasks. I can dump the status of everything
like this:
schtasks /query /fo csv /v > file.csv
the /fo switch is for the format and /v switch makes it verbose. this is
the only way to know if the task has run or not.
The output file looks like this (output truncated):
(1st line)
"HostName","TaskName","Next Run Time","Status","Logon
Mode","Last Run Time","Last Result","Creator","Schedule","Task
To Run","Start In","Comment","Scheduled Task State","Scheduled
Type","Start Time","Start Date","End Date","Days","Months","Run
As User","Delete Task If Not Rescheduled","Stop Task
If Runs X Hours and X Mins","Repeat: Every","Repeat:
Until: Time","Repeat: Until: Duration","Repeat:
Stop If Still Running","Idle Time","Power Management"
(2nd line)
"server","jobname","09:00:00, 16-10-2008","","Interactive
only","09:00:00, 07-10-2008","0","user","At 09:00
every day, starting 18-01-2008","C:\Program Files\SQLyog
Enterprise\sja.exe "afdgroep_progbeh.xml" -l"C:\Documents and
Settings\user\Application Data\SQLyog\sja.log"
-s"C:\Documents and Settings\user\Application
Data\SQLyog\sjasession.xml"","N/A","N/A","Enabled","Daily
","09:00:00","18-01-2008","N/A","Everyday","N/A","domain\administrator","Disabled","Disabled","Disabled","Disabled","Disabled","Disabled","Disabled","Disabled
(no, I did not write this scheduled job)
using TEXT::CSV I can parse the first line, but it stops with the
second:
#!perl
use warnings;
use strict;
use Text::CSV;
my $csv_file = "c:/tmp/dump.csv";
open (CSV, "<", $csv_file) or die "$!\n" ;
my $csv_object = Text::CSV->new();
while (<CSV>) {
if ($csv_object->parse($_)) {
my @columns = $csv_object->fields();
print "@columns\n" ;
}
else {
my $error = $csv_object->error_diag();
print "oeps: $error\n";
}
}
again sorry, all truncated (very long lines)
C:\tmp>test.pl
HostName TaskName Next Run Time Status Logon Mode Last Run Time Last
Result Crea
tor Schedule Task To Run Start In Comment Scheduled Task State Scheduled
Type St
art Time Start Date End Date Days Months Run As User Delete Task If Not
Reschedu
led Stop Task If Runs X Hours and X Mins Repeat: Every Repeat: Until:
Time Repea
t: Until: Duration Repeat: Stop If Still Running Idle Time Power
Management
opes:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
I think it has to do with the long paths in the task to run field,
because when I try the same code at another machine with a 'normal'
(shorter) path to run, I get the desired output.
TIA
I need to check the status of some schedule tasks in a windows server. At
my $JOB we use nagios, so I thouth, let's write a plugin (I could not
find anything at the nagiosexchange).
windows 2k3 has a command schtasks. I can dump the status of everything
like this:
schtasks /query /fo csv /v > file.csv
the /fo switch is for the format and /v switch makes it verbose. this is
the only way to know if the task has run or not.
The output file looks like this (output truncated):
(1st line)
"HostName","TaskName","Next Run Time","Status","Logon
Mode","Last Run Time","Last Result","Creator","Schedule","Task
To Run","Start In","Comment","Scheduled Task State","Scheduled
Type","Start Time","Start Date","End Date","Days","Months","Run
As User","Delete Task If Not Rescheduled","Stop Task
If Runs X Hours and X Mins","Repeat: Every","Repeat:
Until: Time","Repeat: Until: Duration","Repeat:
Stop If Still Running","Idle Time","Power Management"
(2nd line)
"server","jobname","09:00:00, 16-10-2008","","Interactive
only","09:00:00, 07-10-2008","0","user","At 09:00
every day, starting 18-01-2008","C:\Program Files\SQLyog
Enterprise\sja.exe "afdgroep_progbeh.xml" -l"C:\Documents and
Settings\user\Application Data\SQLyog\sja.log"
-s"C:\Documents and Settings\user\Application
Data\SQLyog\sjasession.xml"","N/A","N/A","Enabled","Daily
","09:00:00","18-01-2008","N/A","Everyday","N/A","domain\administrator","Disabled","Disabled","Disabled","Disabled","Disabled","Disabled","Disabled","Disabled
(no, I did not write this scheduled job)
using TEXT::CSV I can parse the first line, but it stops with the
second:
#!perl
use warnings;
use strict;
use Text::CSV;
my $csv_file = "c:/tmp/dump.csv";
open (CSV, "<", $csv_file) or die "$!\n" ;
my $csv_object = Text::CSV->new();
while (<CSV>) {
if ($csv_object->parse($_)) {
my @columns = $csv_object->fields();
print "@columns\n" ;
}
else {
my $error = $csv_object->error_diag();
print "oeps: $error\n";
}
}
again sorry, all truncated (very long lines)
C:\tmp>test.pl
HostName TaskName Next Run Time Status Logon Mode Last Run Time Last
Result Crea
tor Schedule Task To Run Start In Comment Scheduled Task State Scheduled
Type St
art Time Start Date End Date Days Months Run As User Delete Task If Not
Reschedu
led Stop Task If Runs X Hours and X Mins Repeat: Every Repeat: Until:
Time Repea
t: Until: Duration Repeat: Stop If Still Running Idle Time Power
Management
opes:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
oeps:
I think it has to do with the long paths in the task to run field,
because when I try the same code at another machine with a 'normal'
(shorter) path to run, I get the desired output.
TIA