Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by ambrus (Abbot)
on Jul 12, 2012 at 07:08 UTC ( [id://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 +tscript.pl line 7. jobtracker is stopped is status of service

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 02:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found