0
Good evening, you guys, I’ve been hitting myself with something for a few days. I am developing an application to connect via SSH in an OLT with shell script and return the "Shows" to a web frontend.
I have a shell script file that connects via SSH in the OLT command below:
show interface gpon 1/1/1 onu
And play the return of the command to the variable list where I treat the result giving some sed and awk.
list=`showOnu | sed '1,2d' | awk '{print $1 "," $2 "," $3 "," $5}'`
echo $list
echo "<table class='table table-hover'>"
echo " <thead>"
echo " <tr>"
echo " <th scope='col'>ID</th>"
echo " <th scope='col'>Serial Number</th>"
echo " <th scope='col'>Oper State</th>"
echo " <th scope='col'>Name</th>"
echo " <th scope='col'></th>"
echo " </tr>"
echo " </thead>"
echo " <tbody>"
for I in $list
do
idonu=`echo $I | cut -d, -f1`
serialnumber=`echo $I | cut -d, -f2`
name=`echo $I | cut -d, -f3`
status=`echo $I | cut -d, -f4`
echo " <tr>"
echo " <th scope='row'>$idonu</th>"
echo " <td>$serialnumber</td>"
echo " <td>$name</td>"
echo " <td>$status</td>"
echo " <td class='text-right'><a href='onu_edit.php?oltid=1&oltinterface=1' class='btn btn-sm btn-info'>Editar</a></td>"
echo " </tr>"
done
echo " </tbody>"
echo "</table>"
Inside the script I adjust the html to create the result.
And I use this in PHP to call the script on the page:
<?php
$a = popen('./conectOlt -f interfaceOnuList -a '.$olt['ip'].' -i '.$slot.' -e '.$olt['id'].'', 'r');
while($b = fgets($a, 2048)) {
echo $b;
ob_flush();flush();
}
pclose($a); ?>
And generates the result that I have in the first image, until there everything right, this working well.
But I was thinking here, there would be no way in the place to create the <table>
in the shell script create a json and return only json to php and work with it creating the table directly in php.
Basically what I want is to create a json with arrey and maybe use a foreach in php to create each line with the information.
Bro, I’m sorry it took so long....
– Giovani Córdova
@Giovanicórdoba, I’m glad it worked out! Note: If the answer helped you solve the problem please consider marking it as correct to help others with a question similar to yours!
– Murilo Portugal