Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Assign value of SHELL COMMAND to a variable in PERL

by ambrus (Abbot)
on Jul 12, 2012 at 07:08 UTC ( #981313=note: print w/replies, xml ) Need Help??

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

You must quote the dollar sign in the qx literal so that perl does not interpret it.

Updates: The other mistake is that you don't remove the newline so "$status" eq "stopped" won't ever be true. But you should probably test for the service running anyway, not for it being stopped. And it might be easier to use a regex match instead of a string equality.

I wouldn't use awk either. (It just causes unnecessary problems with quoting interacting with ssh here.) (No it doesn't, because the pipeline is not passed through ssh but ran in the local shell. Sorry.) Just run the init script and match the output with a perl regex, such as

my $status = qx{ssh r01mn1 /etc/init.d/hadoop-0.20-mapreduce-jobtracke +r status}; if ( "$status" !~ /\brunning\b/ ) { print "JOBTRACKER SERVICE is not running\n"; }

Btw, I kept running to interpolation mistakes with $1 when writing perl scripts driving gnuplot, because I'm both interpolating values computed in perl to the gnuplot commands and passing literal $1 thingies that gnuplot interprets as column number expressions.

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

    warn provides the output below

    warn provides the output as status=(((jobtracker is stopped ))) at tes line 7. jobtracker is stopped is status of service

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981313]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2018-03-20 11:51 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (250 votes). Check out past polls.