Hello there, how you guys doing? Hope well.
I'm trying to write a perl script which will receive command line arguments and pass it to system.
#!/usr/local/bin/perl
use strict;
use warnings;
# Check if program is being executead as root
if ("$>" ne "0") {
print "This program can't be executed as root\n";
exit 2
}
# Get running vm's
my @get_vm_list = (`xl list`);
sub show_vm_list {
print @get_vm_list;
}
my $vm_run = pop @ARGV ;
my %rec_args = ( vmlist => \&show_vm_list,
getdomid => \&get_dom_id,
);
my $arg = shift @ARGV;
if (defined $arg && exists $rec_args{$arg}) {
$rec_args{$arg}->();
}
OK
here is my function which I'm trying to get working
sub get_dom_id {
my $XENDOMID = "xl list| DOM_ID=`fgrep $vm_run` | awk '{print $
+2}'` && VNCPORT=`ps x \
| fgrep -m 1 "domid $DOM_ID" | awk '{print $1}'` && sockstat -4l | fgr
+ep $VNCPORT | awk '{print $6}'";
print `$DOMID`;
}
I have already tried set system environment using $ENV{'MYVAR'} without success
Any Directions will be appreciated, thanks in advance
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|