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

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.


Comment on Re: Assign value of SHELL COMMAND to a variable in PERL
Select or Download Code
Re^2: Assign value of SHELL COMMAND to a variable in PERL
by rahulruns (Sexton) on Jul 12, 2012 at 07:56 UTC

    warn provides the output below

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981313]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2014-08-20 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (109 votes), past polls