in reply to Assign value of SHELL COMMAND to a variable in PERL

I suspect that the problem might be that the system call is resulting in output to STDERR, rather than STDOUT. To redirect, try adding 2>&1 like this:
my $status = qx{ ssh r01mn1 /etc/init.d/hadoop-0.20-mapreduce-jobtrack +er status 2>&1 | awk '{print $3}'};

Be sure to put it before the pipe, otherwise you won't be piping anything to awk. Did that help at all?

Replies are listed 'Best First'.
Re^2: Assign value of SHELL COMMAND to a variable in PERL
by ambrus (Abbot) on Jul 12, 2012 at 07:36 UTC

    Good guess, it's definitely worth a try, but it seems the Debian init scripts do write the status output to stdout.

Re^2: Assign value of SHELL COMMAND to a variable in PERL
by rahulruns (Scribe) on Jul 12, 2012 at 06:56 UTC

    The output is same even after change

    output [root@r01mgt ~]# perl testscript.pl jobtracker is stopped is status of service
      Out of curiosity, what do you get w/o the pipe to awk?
Re^2: Assign value of SHELL COMMAND to a variable in PERL
by jessarah (Initiate) on Jul 12, 2012 at 11:03 UTC
    May be this is a more complicated way, but works with me:
    my $lcmd="pwd"; open (INPUT,"($lcmd) 2>&1 |"); @ltext = <INPUT>; close (INPUT); my $result=$ltext[0]; print("Output of pwd: $result");

    *Jes