josanabr wrote:
Hi,

Hello,

I having problems with a perl module implemented in Sun Grid Engine.
This perl module (script) continuously watches the state of jobs
submitted to my cluster.
Every job can reach some of these states:
r - run
t - transfer
q - queued
s - suspended
w - waiting

In order to identify the current state of any job, the module(script)
invokes the program 'qstat'. For instance, this is a regular output of
this command:
4426 0.55500 data       jas          r   03/15/2009 15:52:19

This output indicates that there is a job who owner is the 'jas' user,
with job id = 4426, submitted on 03/15/2009 15:52:19  and it is
running (r).

I wrote the following perl script:

#!/usr/bin/perl -w

#!/usr/bin/perl
use warnings;
use strict;

$job_id = 4426;
my @x = grep(/^\s+$job_id\s/,`qstat`);
my @estado = split(/\s+/,$x[0]);
print $estado[5];
if ($estado[5] eq "r") {
   print "ok";
} else {
   print "bad";
}

and it works as I expect, it prints 'rok', while the program is
running.

Now, I have tried to modify the 'sge.pm' module (script), but when I
define a variable, for instance:
my @x = grep(/^\s+$job_id\s/,`qstat`);

and print the value of '@x' I got nothing.

Your regular expression /^\s+$job_id\s/ says that there *must* be whitespace before the first field but your example data says there is *no* whitespace before the first field? You probably want to use /^\s*$job_id\s/ instead which says that leading whitespace is optional.

If your data varies between having leading whitespace and not having leading whitespace then your second problem is that:

my @estado = split(/\s+/,$x[0]);

will store the state data in $estado[5] if there is leading whitespace or in $estado[4] if there is *no* leading whitespace. You need to use the "special" split expression of a single space character:

my @estado = split(' ',$x[0]);

and that way the state data will always be in $estado[4].




John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to