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

  • Home
  • SEARCH
  • 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 9130787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:01:32+00:00 2026-06-17T08:01:32+00:00

For a project I created a bash script that writes VNC ports with the

  • 0

For a project I created a bash script that writes VNC ports with the corresponding VM in a text file. I’m trying to output the correct VNC port with the corresponding VM. The output of the bash script is something like:

 Port: 5903    VM : i-2-3-VM
 Port: 5904    VM : i-4-6-VM
 Port: 5902    VM : r-4-VM
 Port: 5901    VM : s-1-VM
 Port: 5900    VM : v-2-VM

The number in each line corresponds to the VNC port.

No i’ve got the VM name in a variable I can use, all tho I used a static value to see if my script actually works. The script outputs the entry $data variable first just as a check. The script should output “r-4-VM”, i think I can fetch previous arrays to fetch the actually port later. But the script doesn’t output the value im looking for in the first place. I know the value exists cause I printed $data earlier as a refference.

<?php
session_start();

$file = file_get_contents('/var/www/html/webpanel/text.txt');

$data = explode(' ', $file);
$array = array($data);

$count = count($array);

print_r($data);


for ($i=0; $i <= $count; $i++) { 


        if (strstr($data[$i] , 'r-4-VM')) {

            print_r($data[$i]);
    }

}
?>
  • 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-06-17T08:01:33+00:00Added an answer on June 17, 2026 at 8:01 am
    <?php
    session_start();
    
    
    $array = file($file);
    
    $count = count($array);
    
    print_r($array);
    
    
    for ($i=0; $i <= $count; $i++) { 
    
    
        if (strstr($array[$i] , 'r-4-VM')) {
    
            print_r($array[$i]);
    }
    
    }
    ?>
    

    Try that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I'm trying to do I've created a shell script that I've added to
I'm trying to run a simple bash script using NSTask and direct the output
Just for fun I created a project that created about 5 GB of memory
I am using VS 2008. When I opened a c# project file created by
I'm trying to setup integrity for my project. Sadly, my bash-fu is poor so
I'm playing around with a bash script, parsing the output of a cURL POST,
I just created a script/run in my project in the following way: #!/usr/bin/env ruby
I created a small script I use for 'cleaning' sitemap file from certain links.
I'm trying to create a short bash script someone could run in cygwin to
I have a project created in visual studios 2010 pro, now opening it ultimate

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.