Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3336366
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:07:36+00:00 2026-05-18T00:07:36+00:00

I am trying to create a script that will take output of a system

  • 0

I am trying to create a script that will take output of a system command and I want to organize the data into an array.

The script is to discover VMs residing on a local ESXi server I have. I am using plink.exe to send the command to the server and then it returns a list of VMs that looks like this.

Vmid   Name                File                 Guest OS      Version   Annotation
128    NS01    [datastore2] NS01/NS01.vmx     ubuntu64Guest   vmx-07
144    NS02    [datastore2] NS02/NS02.vmx     ubuntu64Guest   vmx-07
208    MX01    [datastore2] MX01/MX01.vmx     ubuntu64Guest   vmx-07
224    SQL01   [datastore2] SQL01/SQL01.vmx   ubuntu64Guest   vmx-07
240    WS01    [datastore2] WS01/WS01.vmx     ubuntu64Guest   vmx-07

How would I take this and make an array out of it? The only columns that really matter are VMID, Name, File

The command I am using to get the output is this.

# Parse ESX\ESXi server for virtual machines that reside on it
system ("$plink \-batch \-pw $esx_password $esx_user\@$esx_host vim-cmdvmsvc/getallvms\n");

Any insight would be great.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:07:36+00:00Added an answer on May 18, 2026 at 12:07 am

    Yes, use backquotes not system if you want to parse the output.

    my $cmd 
        = "$plink -batch -pw $esx_password $esx_user\@$esx_host "
        . "vim-cmdvmsvc/getallvms"
        ;
    my @lines = `$cmd`;
    

    system will just use your standard out.

    Not sure why you were escaping the dashes, though…

    Once you have the output, you can do the following (note that I leveraged the fixed-length fields look):

    foreach ( @line ) { 
        # this is the get-it-and-do-something-else-with-it version
        my ( $vmid, $name, $file )
            = substr( $_, 0, 47 ) =~ m/^ ( \d+ ) \s+ ( \S+ ) \s+ (.*\S) \s* $/x
            ;
    
        # OR the store-it-in-an-array-of-hashes version:
        @{ my $h = {}}{ qw<VMID Name File> }
            = substr( $_, 0, 47 ) =~ m/^ ( \d+ ) \s+ ( \S+ ) \s+ (.*\S) \s* $/x
            ;
        push @array, $h if %$h;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.