Brandon
Brandon

Reputation: 910

Nested while loop not executing

I have the following code, the only problem is that when the code gets to the nested while loop it skips it, I'm assuming the condition is not being met, but can anyone see something I amy have done wrong? I have verified that all the flags that I give to the script are correct and that the job_name is what I think it should be.

open $alOut,
     "/home/usr/bin/test.pl -j EW-% -j RA-% -l 0 | grep `date \"+%m/%d/%Y\"` | sort -k 3,3|";
while (<$alOut>) {
    chomp;
    my ($job_name, $date, $start_time, $end_time, $duration,
        $state, $return, $expected_end_time) = split(/\s+/, $_);

    # Go to next iteration if jobname is EW-INTERNAL-AUTOSYS,
    # EW-INTERNAL-DB-LONGQUERY-ALERT, EW-INTERNAL-DB-LONGQUERY-ALERT,
    # EW-CIIM-ADJ-TRIGGER, or EW-S140-ADJ-TRIGGER
    if (($job_name eq "EW-INTERNAL-AUTOSYS") ||
        ($job_name eq "EW-INTERNAL-DB-LONGQUERY-ALERT") ||
        ($job_name eq "EW-INTERNAL-SYSUP") ||
        ($job_name eq "EW-CIIM-ADJ-TRIGGER") ||
        ($job_name eq "EW-S140-ADJ-TRIGGER"))
        {
            next;
        }

    #Expected Start Time
    open $alOut2,
         "/home/usr/bin/test.pl -j $job_name -q -l 0 | grep -E `condition:|start_times:`";
    while (<$alOut2>) { .... }
}

Upvotes: 0

Views: 413

Answers (2)

Sean
Sean

Reputation: 29772

You should always check the value returned by open:

open "...whatever..." or die "Can't open: $!";

That will probably tell you all you need to know, but offhand, I can see two problems:

  1. The second open isn't terminated by a | character.
  2. The backticks after the grep should be apostrophes.

Upvotes: 3

Andy
Andy

Reputation: 4866

You should check for errors from open:

open $fh, ... or die "Can't open: $!";

And in this grep:

grep `condition:|start_times:`

you probably want regular single quotes ('), not backticks, the shell is going to try to run a command called condition:. And I think you are missing a final | in that command.

Upvotes: 5

Related Questions