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]);
}
}
?>
Try that.