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

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

by knight.neo (Initiate)
on Jan 22, 2019 at 19:07 UTC ( [id://1228836]=note: print w/replies, xml ) Need Help??


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

Hi haukex, Absolutely , xl is part of xen-tools. xl is used to manipulate virtual machines as other system parameters as well. Here is a tipical output of "xl list" ( used to list running virtual machines ) I am using FreeBSD as dom0. When I start a VM on HVM mode, I use VNC to access vm console.
# xl list Name ID Mem VCPUs State + Time(s) Domain-0 0 18442 2 r----- + 16256.2 git 1 1023 2 -b---- + 14499.4 zabbix 2 512 1 -b---- + 3228.6 jenkins 3 4096 2 -b---- + 21733.3 openbsd 4 2048 1 -b---- + 1202.6 wiki 5 2048 1 -b---- + 1140.4 builder 6 4096 2 -b---- + 206.9
This perl script which you guys helped, do the follow: "pxl vmlist" ( which will return xl list ), and "pxl getvnc jenkins" ( which will return vnc port listening of that VM ) "127.0.0.1:5906" Next steps, I will provide ssh port forward and connect to it :) Thanks again

Replies are listed 'Best First'.
Re^5: system commands/shell and perl variables.
by haukex (Archbishop) on Jan 23, 2019 at 20:15 UTC

    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://1228836]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-20 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found