Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^5: system commands/shell and perl variables.

by haukex (Archbishop)
on Jan 23, 2019 at 20:15 UTC ( [id://1228887]=note: print w/replies, xml ) Need Help??


in reply to Re^4: system commands/shell and perl variables.
in thread system commands/shell and perl variables.

Since I don't have all the commands you're using on my system, here are just some general tips. Your command | fgrep | awk sequences can be rewritten in Perl in the following manner, using xl list as an example. You can write these loops one after the other, first getting the ID, then the VNC port, and finally for the IP address.

use warnings; use strict; use IPC::System::Simple qw/capturex/; my $vm_run = 'zabbix'; my $id; for ( capturex('xl','list') ) { # loop over lines of command output chomp; # remove newline my @F = split; # split the line into fields on whitespace (like a +wk) if ( $F[0] eq $vm_run ) { # match on the first field $id = $F[1]; # store the second field #last; # would be the equivalent of fgrep -m1 } } print "ID: $id\n"; # prints "ID: 2" in this example

Also, I suspect print `$DOMID`; isn't right, you probably don't want to execute the contents of the $DOMID as a command (that's what the backticks will do)? You probably want a simple print "$DOMID\n"; instead.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-03-29 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found